Robots & Pencils
RoboPress
Published in
3 min readJun 13, 2018

--

Dynamic Type is an Accessibility feature introduced by Apple in iOS 7 that allows users to have greater control over the size of the size of text displayed in their apps. Some apps have seen over 20% of their users enable dynamic type, so it is worth considering taking the time to implement so that your users can have the best experience.

Working with Dynamic Type

There are two ways you can turn on Dynamic Type in code, using text styles or UI font metrics. Both are fairly straightforward to implement.

Text Styles

Apple specifies a set of text styles, including common use cases like Body, Title1, Detail, etc. As of iOS 12, there are 11 supported text styles.

When working with text styles, you simply query for the font for a specific text style. The SDK will return a font for that style, sized to match the user’s Dynamic Type setting.

Doing so takes only two lines:

In #1, we are querying the system for the font that matches that text style given the user’s Dynamic Type setting.

#2 makes sure that, if the user changes their font size while your application is running, the label’s font will update based on the new setting.

UI Font Metrics

In addition to specifying a text style, you can also use a font metric. With this method, you provide a font, and the system returns a scaled version of that font to match the user’s current Dynamic Type settings.

Once again, this can be accomplished in only two lines:

The above code adjusts the label’s font size based on the font size on the device — automatically!

#1 takes the font already on the label (whether from interface builder or another source) and scales it to match the user’s settings.

Similar to working with text styles, #2 is necessary to have your font update when the user updates their Dynamic Type settings.

Interface Builder

In addition to being set in code, the adjustsFontForContentSizeCategory property can be set in Interface Builder.

Testing Dynamic Type

Once you have set up your interface to work with Dynamic Type, you can test it using the Settings app.

To toggle the change:

  • Go to the Settings app.
  • Navigate to General -> Accessibility -> Larger Text.
  • Toggle Larger Accessibility Sizes to ON.
  • Drag the slider at the bottom of the screen to change the text size system wide.
  • Switch back to your app to see the changes.

Conclusion

Dynamic Type is fairly simple to implement, although you will have to spend some additional effort testing your interfaces on different settings to verify that they adjust appropriately.

To learn more about how Apple recommends using Dynamic Type, you can read the Human Interface Guidelines.

--

--

A digital innovation firm. We help our clients use mobile, web & frontier technologies to transform their businesses and create what’s next.