Dynamic Type in iOS
Priya Rajagopal
www.priyaontech.com
Twitter: @rajagp
CocoaHeads Ann Arbor
May, 2014
Fonts
!   Text content represented using fonts (UIFont)
!   Fonts = glyphs that share typeface, typestyle and size
!   Typ...
Text Styles
!   Introduced in iOS7
! UITextKit
!   Describe intended use of text – Headings, SubHeadings,Body
!   Every te...
Text Style
Constants
•  UIFontTextStyleHeadline
•  UIFontTextStyleSubheadline
•  UIFontTextStyleBody
•  UIFontTextStyleFoo...
What is Dynamic Type?
!   Technology introduced in iOS7
!   Users adjust text size preferences
!   Settings
!   Accessibil...
www.priyaontech.com 6
TextStyles & Dynamic Type
!   Fonts associated with text styles change dynamically based
on user preferences
!   To suppor...
www.priyaontech.com 8
Font Descriptors
!   Introduced in iOS7 (UIFontDescriptor)
!   Describe fonts
!   Dictionary of font attributes
UIFontDesc...
Your own Text Style
(with Dynamic Type Support)
!   Get font descriptor for an existing TextStyle
UIFontDescriptor* fontDe...
Detecting Text Size Changes
! UIContentSizeCategoryDidChangeNotification
!   Register for notification with NSNotification...
Demo
www.priyaontech.com 12
Upcoming SlideShare
Loading in …5
×

Dynamic types in iOS

1,206 views

Published on

iOS7 introduced Dynamic Types. This technology allows apps to dynamically adjust their text content based on user's text size preferences. This is a short presentation on Dynamic Type.

Published in: Mobile, Technology, Art & Photos
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,206
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Dynamic types in iOS

  1. 1. Dynamic Type in iOS Priya Rajagopal www.priyaontech.com Twitter: @rajagp CocoaHeads Ann Arbor May, 2014
  2. 2. Fonts !   Text content represented using fonts (UIFont) !   Fonts = glyphs that share typeface, typestyle and size !   Typeface : Helvetica-Neue, Arial, Times… ! TypeStyle : bold, normal, italic… !   System Fonts + (UIFont *)systemFontOfSize:(CGFloat)fontSize; + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; + (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; !   Custom + (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize; !   Text Styles … www.priyaontech.com 2
  3. 3. Text Styles !   Introduced in iOS7 ! UITextKit !   Describe intended use of text – Headings, SubHeadings,Body !   Every text style associated with a font + (UIFont *)preferredFontForTextStyle:(NSString *)style www.priyaontech.com 3
  4. 4. Text Style Constants •  UIFontTextStyleHeadline •  UIFontTextStyleSubheadline •  UIFontTextStyleBody •  UIFontTextStyleFootnote •  UIFontTextStyleCaption1 •  UIFontTextStyleCaption2 www.priyaontech.com 4 Text Styles are implemented using Dynamic Type …
  5. 5. What is Dynamic Type? !   Technology introduced in iOS7 !   Users adjust text size preferences !   Settings !   Accessibility !   Apps react by dynamically adjust displayed text content !   Enhanced Readability !   Customized to user’s preferences www.priyaontech.com 5
  6. 6. www.priyaontech.com 6
  7. 7. TextStyles & Dynamic Type !   Fonts associated with text styles change dynamically based on user preferences !   To support dynamic type, use TextStyles + (UIFont *)preferredFontForTextStyle:(NSString *)style www.priyaontech.com 7
  8. 8. www.priyaontech.com 8
  9. 9. Font Descriptors !   Introduced in iOS7 (UIFontDescriptor) !   Describe fonts !   Dictionary of font attributes UIFontDescriptorTraitsAttribute, UIFontDescriptorFamilyAttribute, UIFontDescriptorTextStyleAttribute, UIFontDescriptorNameAttribute, UIFontDescriptorFaceAttribute, UIFontDescriptorSizeAttribute … !   Get/Create font from descriptor + (UIFont *)fontWithDescriptor:(UIFontDescriptor *)descriptor size: (CGFloat)pointSize !   Get descriptor for font - (UIFontDescriptor *)fontDescriptor www.priyaontech.com 9
  10. 10. Your own Text Style (with Dynamic Type Support) !   Get font descriptor for an existing TextStyle UIFontDescriptor* fontDesc = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline]; !   Update descriptor. UIFontDescriptor* updatedFontDesc = [fontDesc fontDescriptorByAddingAttributes:@{UIFontDescriptorTraitsAttribute:@{UIFontS ymbolicTrait:[NSNumber numberWithInteger:UIFontDescriptorTraitItalic]}}]; !   Create new font from updated font descriptor UIFont* myFont = [UIFont fontWithDescriptor:updatedFontDesc size:fontDesc.pointSize* scale]; * You can’t change the font family. It will be the system font type- Helvetica-Neue. www.priyaontech.com 10
  11. 11. Detecting Text Size Changes ! UIContentSizeCategoryDidChangeNotification !   Register for notification with NSNotificationCenter !   React by invalidating existing fonts and getting new ones !   Adjust container bounds to account for new content size !   Auto layout ! invalidateIntrinsicContentSize/ sizeToFit www.priyaontech.com 11
  12. 12. Demo www.priyaontech.com 12

×