Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Session 230 - Advanced Attributed Strings for iOS

wwdcman
June 25, 2012
75

Session 230 - Advanced Attributed Strings for iOS

wwdcman

June 25, 2012
Tweet

Transcript

  1. These are confidential sessions—please refrain from streaming, blogging, or taking

    pictures Desktop class effects on a mobile device Session 230 Advanced Attributed Strings for iOS Ian Baird Label Engineer
  2. NSKernAttributeName Advanced Attributes •Kerning will vary from font to font

    •Enable auto-kerning with nil or [NSNull null] •Disable kerning – @0.0
  3. NSKernAttributeName Advanced Attributes •Kerning will vary from font to font

    •Enable auto-kerning with nil or [NSNull null] •Disable kerning – @0.0 •Any other value adjusts the kerning by a number of points @{NSKernAttributeName: [NSNull null]}
  4. NSKernAttributeName Advanced Attributes •Kerning will vary from font to font

    •Enable auto-kerning with nil or [NSNull null] •Disable kerning – @0.0 •Any other value adjusts the kerning by a number of points @{NSKernAttributeName: @2.0}
  5. NSKernAttributeName Advanced Attributes •Kerning will vary from font to font

    •Enable auto-kerning with nil or [NSNull null] •Disable kerning – @0.0 •Any other value adjusts the kerning by a number of points @{NSKernAttributeName: @-2.0}
  6. Line height NSParagraphStyle •Controls the line height - minimumLineHeight /

    maximumLineHeight ▪ Usually set to same value ▪ Moves baseline
  7. Line height NSParagraphStyle •Controls the line height - minimumLineHeight /

    maximumLineHeight ▪ Usually set to same value ▪ Moves baseline ▪ Used by Stocks
  8. NSParagraphStyle •Controls the gap between lines and paragraphs - lineSpacing

    ▪ a.k.a. “leading” ▪ included in line fragment heights Spacing
  9. NSParagraphStyle •Controls the gap between lines and paragraphs - lineSpacing

    ▪ a.k.a. “leading” ▪ included in line fragment heights Spacing
  10. NSParagraphStyle •Controls the gap between lines and paragraphs - lineSpacing

    ▪ a.k.a. “leading” ▪ included in line fragment heights Spacing
  11. •Controls the gap between lines in the paragraph - lineSpacing

    Spacing NSParagraphStyle This paragraph is using the normal line spacing value.
  12. •Controls the gap between lines in the paragraph - lineSpacing

    Spacing NSParagraphStyle The line spacing value for this paragraph is 30.0. 30.0
  13. •Controls the gap between lines and paragraphs - paragraphSpacing More

    spacing NSParagraphStyle This paragraph has 30.0 paragraph spacing. This paragraph has 0 spacing values. 30.0
  14. •Controls the gap between lines and paragraphs - paragraphSpacingBefore More

    spacing NSParagraphStyle This paragraph has 0 spacing values. The spacing value before this paragraph is 30.0. 30.0
  15. •Controls left and right margins - headIndent Indentation NSParagraphStyle This

    is a normal paragraph that has no indentation specified.
  16. •Controls left and right margins - firstLineHeadIndent Indentation NSParagraphStyle This

    is a normal paragraph that has no indentation specified. 30.0
  17. Text Effects in Your App Using advanced text effects to

    beautify and enhance John Appleseed
  18. UIKit caveats Text Effects in Your App ▪ UIKit supplies

    default values for NSFontAttributeName—[UIFont systemFontWithSize:DEFAULT_FONT_SIZE]
  19. UIKit caveats Text Effects in Your App ▪ UIKit supplies

    default values for NSFontAttributeName—[UIFont systemFontWithSize:DEFAULT_FONT_SIZE] NSForegroundColorAttributeName—[UIColor blackColor]
  20. UIKit caveats Text Effects in Your App ▪ UIKit supplies

    default values for NSFontAttributeName—[UIFont systemFontWithSize:DEFAULT_FONT_SIZE] NSForegroundColorAttributeName—[UIColor blackColor] NSKernAttributeName—@0.0
  21. UIKit caveats Text Effects in Your App ▪ UIKit supplies

    default values for NSFontAttributeName—[UIFont systemFontWithSize:DEFAULT_FONT_SIZE] NSForegroundColorAttributeName—[UIColor blackColor] NSKernAttributeName—@0.0 NSLigatureAttributeName—@0
  22. NSStringDrawing API •Simple drawing/sizing methods - (void)drawInRect:(CGRect)rect; - (void)drawAtPoint:(CGPoint)point; -

    (CGSize)size; •Extended drawing/sizing methods - (void)drawWithRect:(CGRect)rect ! options:(NSStringDrawingOptions)options ! context:(NSStringDrawingContext *)context; - (CGRect)boundingRectWithSize:(CGSize)size ! options:(NSStringDrawingOptions)options ! context:(NSStringDrawingContext *)context;
  23. NSStringDrawing API •Simple drawing/sizing methods - (void)drawInRect:(CGRect)rect; - (void)drawAtPoint:(CGPoint)point; -

    (CGSize)size; •Extended drawing/sizing methods - (void)drawWithRect:(CGRect)rect ! options:(NSStringDrawingOptions)options ! context:(NSStringDrawingContext *)context; - (CGRect)boundingRectWithSize:(CGSize)size ! options:(NSStringDrawingOptions)options ! context:(NSStringDrawingContext *)context;
  24. Values NSStringDrawingOptions •Supported values NSStringDrawingUsesLineFragmentOrigin NSStringDrawingTruncatesLastVisibleLine NSStringDrawingUsesFontLeading •Specifying multiple options

    ▪ Truncate last visible line and use line fragment origin ▪ NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin
  25. NSStringDrawingUsesLineFragmentOrigin Origin •The origin of the rect determines where the

    rendering begins - (void)drawWithRect:(CGRect)rect options:context:
  26. •Origin at baseline •Default mode for extended API •Usually used

    with a single line of text NSStringDrawingUsesLineFragmentOrigin Baseline Origin Baseline Origin AaBbCcDdEeFfGgHhIiJj
  27. •Origin at baseline •Default mode for extended API •Usually used

    with a single line of text NSStringDrawingUsesLineFragmentOrigin not set NSStringDrawingUsesLineFragmentOrigin Baseline Origin Baseline Origin AaBbCcDdEeFfGgHhIiJj
  28. •Origin at upper-left of line fragment •Default mode for simple

    API NSStringDrawingUsesLineFragmentOrigin Line Fragment Origin Origin AaBbCcDdEe FfGgHhIiJj
  29. •Origin at upper-left of line fragment •Default mode for simple

    API •Usually used with multiple lines of text NSStringDrawingUsesLineFragmentOrigin Line Fragment Origin Origin AaBbCcDdEe FfGgHhIiJj
  30. •Origin at upper-left of line fragment •Default mode for simple

    API •Usually used with multiple lines of text NSStringDrawingUsesLineFragmentOrigin Line Fragment Origin Origin AaBbCcDdEe FfGgHhIiJj
  31. Demo Recap •Use advanced text effects to communicate emphasis, selection

    •Make your text more legible •Drawing on the background works
  32. Demo Recap •Use advanced text effects to communicate emphasis, selection

    •Make your text more legible •Drawing on the background works ▪ Use UIImage and drawInRect:
  33. Demo Recap •Use advanced text effects to communicate emphasis, selection

    •Make your text more legible •Drawing on the background works ▪ Use UIImage and drawInRect: ▪ Do not manipulate UI elements from the background queue
  34. More Information Jake Behrens UI Frameworks Evangelist [email protected] Documentation UIKit

    Framework Reference http://developer.apple.com/library/ios/ Apple Developer Forums http://devforums.apple.com
  35. Related Sessions Introduction to Attributed Strings for iOS Mission Wednesday

    3:15PM Core Text and Fonts Russian Hill Wednesday 4:30PM Keyboard Input in iOS Russian Hill Wednesday 2:00PM