Chapters

Hide chapters

Auto Layout by Tutorials

First Edition · iOS 13 · Swift 5.1 · Xcode 11

Section II: Intermediate Auto Layout

Section 2: 10 chapters
Show chapters Hide chapters

Section III: Advanced Auto Layout

Section 3: 6 chapters
Show chapters Hide chapters

11. Dynamic Type
Written by Jayven Nhan

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Dynamic Type is an iOS feature that enables app content to scale according to the user’s font size preference. For the millions of people without perfect vision, having support for Dynamic Type makes all the difference. Without it, your app’s user experience will likely suffer.

Visual impairment is one of the world’s leading disabilities. Yet, most apps on the App Store fail to support Dynamic Type. But there’s no reason your apps have to fall into that category.

In this chapter, you’ll learn about:

  • Reasons for supporting Dynamic Type.
  • Supporting Dynamic Type on an existing app.
  • Preferred font sizes.
  • Growing and shrinking text.
  • Supporting Dynamic Type using custom fonts.
  • Growing and shrinking non-text UI elements.
  • Managing layout changes based on font preferences.

By the end of this chapter, you’ll know how to add support for Dynamic Type in your iOS apps.

Why Dynamic Type?

Dynamic Type makes your app usable by a broader audience, regardless of age or eyesight. In this section, you’ll learn about five reasons to support Dynamic Type.

Readability

Having a readable app is important. Supporting larger font sizes may not make a huge difference to someone with near-perfect vision, but many do not fall into that category. Look at the following image:

Temporary or chronic injuries

You may think that users seldom need to change their text size preferences once they find a size that works. However, sometimes a person’s eyesight deteriorates. Whether the deterioration is temporary or chronic, Dynamic Type can help ease the burden with large font size.

Competition differentiation

Building apps accessible for everyone isn’t always easy, but an accessible app differentiates itself from non-accessible apps. A comprehensive feature-packed app isn’t worth much to users if they can’t see what they’re doing. When it comes to downloading apps, users will almost always choose the one that brings more value and is easier to use, so make sure your app is beautiful at all text sizes.

High user retention rate over time

If your app accommodates all users regardless of how well they see, users won’t need to go looking for an alternate solution should they ever need to increase the app’s font size. Consequently, the app retention rate goes up over time.

Monetary gains

You can gain more users by ensuring that your app works equally great for all who use it. So, don’t regularly tax your user’s brainpower, which can make using your app exhausting. Instead, let users access their font preferences so they can use your app with relative ease. This makes for happy users, and happy users can’t wait to come back for more.

Setting the preferred font size

Before you begin, the first step is to change your device’s preferred font size. On iOS 13, follow these steps:

Making labels support Dynamic Type

Dynamic Type almost works right out of the box. With Storyboards and text styles, you can size a label’s text.

Making custom fonts support Dynamic Type

Making custom fonts dynamic requires a few more steps. At the time of writing this chapter, Interface Builder does not support setting up dynamic custom fonts. Consequently, you need to set a dynamic custom font using code.

Managing layouts based on the text size

In addition to having readable text, you need your app to look good when users change their text size. In code, you’ll need to identify the user’s preferred font size to make that happen. The first way to identify the user’s preferred font size is to get the view’s trait collection.

Supporting Dynamic Type with UITableView

Dynamic Type works right out of the box with the standard UITableView. By default, the header and cell height dynamically scale to fit the header and cell content.

Supporting Dynamic Type with UICollectionView

The standard UICollectionView requires more work to support self-sizing cells. Specifically, when you use a collection view for non-line based layouts, you’ll need to set up a custom UICollectionViewLayout.

Preparing custom collection view layouts

Open CollectionViewLayout.swift. Add the following properties to CollectionViewLayout:

Creating collection view layout attributes

Add the following code to makeAttributes(for:):

Overriding layout attributes methods

Add the following method overrides to CollectionViewLayout:

Setting the collection view content size

Add the following property and method overrides to CollectionViewLayout:

Setting up the collection view layout delegate

Open CollectionViewController.swift.

Invalidating collection view layout for trait collection

Finally, add the following code to CollectionViewController:

Challenges

Build and run. Tap the Text Styles bar button item, and you’ll see InfoViewController. Your challenge is to make InfoViewController support Dynamic Type.

Key points

  • The Dynamic Type feature allows users to scale content sizes based on the device’s font size preference.
  • Supporting Dynamic Type makes your app usable for a broader audience, which comes with benefits, including being different from the competition and increasing app retention rate.
  • Apps using Apple’s SF font can easily support Dynamic Type.
  • You can implement custom fonts with Dynamic Type.
  • You can scale non-text user interface elements according to the font size preferences.
  • Stack view makes it easy to make layout changes according to the font preferences.
  • When a cell uses Auto Layout, the standard UITableView supports Dynamic Type out of the box.
  • For collection views using non-line based layouts, you can support Dynamic Type using custom collection view layouts.
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now