iOS 7 introduced Dynamic Type which allows the user to specify the font size in Settings.  The easiest way to support dynamic type is to use one of Apple’s pre defined Font Text Style’s below.

Swift 3

UIFontTextStyle.title1
UIFontTextStyle.title2
UIFontTextStyle.title3
UIFontTextStyle.headline
UIFontTextStyle.subheadline
UIFontTextStyle.body
UIFontTextStyle.callout
UIFontTextStyle.footnote
UIFontTextStyle.caption1
UIFontTextStyle.caption2

Swift 2.2

UIFontTextStyleTitle1
UIFontTextStyleTitle2
UIFontTextStyleTitle3
UIFontTextStyleHeadline
UIFontTextStyleSubheadline
UIFontTextStyleBody
UIFontTextStyleCallout
UIFontTextStyleFootnote
UIFontTextStyleCaption1
UIFontTextStyleCaption2

 

Here is a code example in Swift 3 of using the Headline font style.

let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .headline)

 

Below is screenshot of all the Font Text Style’s in action using the San Francisco font in iOS 9.

UIFontTextStyle

For further reading see the Apple Documentation for the UIFontDescriptor.

 

If you need a monospace font for displaying numbers in iOS 9 and newer you can use monospacedDigitSystemFont(ofSize fontSize: CGFloat, weight: CGFloat).

let label = UILable()
label.font = UIFont.monospacedDigitSystemFont(ofSize: 30, weight: 0.3)

 

Get insights into your Apple Search Ads performance with Kitemetrics by Kitefaster.  Kitemetrics helps you optimize your bids and keywords to increase revenue.

Dynamic Type in iOS using UIFontTextStyle
Translate »