Dynamic Type is a system that allows users to choose the font size that works best for them. It can be used to reduce the default font size in order to fit more content on screen, or more importantly, increase the default font size to aid those with farsightedness or other visual ailments. You'll quickly notice that Dynamic Type has many names, but they all refer to the same concept. In Apple's accessibility settings, it's called **Larger Text.** In Apple's developer marketing, it's called **Dynamic Type**. In code, it's called `preferredContentSizeCategory`. Furthermore, there are two different categories of Dynamic Type; standard sizes and accessibility sizes. Standard sizes are available by default on all iOS devices. They range from `.extraSmall` to `.extraExtraExtraLarge`. The default iOS size is `.medium`. You can see all possible values in the documentation of [UIContentSizeCategory](https://developer.apple.com/documentation/uikit/uicontentsizecategory). There is an additional set of values that can increase the font size even more. These can be activated in Settings -> Accessibility -> Display & Text Size -> Larger Text -> Large Accessibility Sizes. If the toggle is activated, the user will be able to increase the text size beyond `.extraExtraExtraLarge`. These sizes range from `.accessibilityMedium` to `.accessibilityExtraExtraExtraLarge`. You can programmatically determine whether or not a given `UIContentSizeCategory` is contained in these sizes by using `myContentSizeCategory.isAccessibilityCategory`. This can be a useful threshold when determining whether or not you should adjust your layout in order to accommodate larger content. %%You can read more about that [here]().%% Dynamic Type has traditionally been thought of as a system-wide setting. Since iOS 15, however, it can be adjusted on a per-app basis. This shouldn't require any specific changes from the developer's point of view. [[Configuring Dynamic Type on your iOS Device]] %% ## Integrating Dynamic Type with Apple's default font in UIKit You can get Dynamic Type working in 2 simple steps. 1- On `UILabel`, set `adjustsFontForContentSizeCategory` to `true` . (It's false by default) 2- Set the font by using `UIFont.preferredFont(forTextStyle:)`. However, there are a few more things to do to have it display correctly. First, you need to set `UILabel.numberOfLines` to `0` (it's `1` by default). This will allow text to reflow on multiple lines. Secondly, in order to avoid orphan words getting cut off at larger text sizes, you should set `UILabel.lineBreakMode` to `.byWordWrapping`. You can wrap this all up in an extension for ease of use: ```swift extension UILabel { func configureForDynamicType() { self.adjustsFontForContentSizeCategory = true self.numberOfLines = 0 self.lineBreakMode = .byWordWrapping } } ``` ## Integrating Dynamic Type with Apple's default font in SwiftUI ## Using Dynamic Type with a custom font in UIKit ## Using Dynamic Type with a custom font in SwiftUI ## Pain points ### Limiting Dynamic Type Size In some cases, you may want to limit the size of dynamic type on ### Side by side content Displaying side-by-side content can be difficult at large text sizes. When multiple pieces of text grow, they compete for horizontal space. ### Text clipping off the left or right edge of the screen ### Text clipped by the bottom of the screen (UIKit) Text being clipped by the bottom of the screen is a common pain point when integrating Dynamic Type. As text becomes larger, it occupies more vertical space and can push content lower on the screen completely off the screen. This issue can often be solved by wrapping your view in a `UIScrollView`. If properly configured, the scroll view will be imperceptable to the user until it's needed. In order to make the process easier, you can use a base view controller that already embeds its content in a scroll view. Much like `UITableViewController` and `UICollectionViewController`, you can use `UIScrollViewController` as a base class for creating screens in which their content does not natively scroll. Here's a reference implementation: ``` class UIScrollViewController: UIViewController { } ``` ### Text clipping off the bottom of the screen (SwiftUI) ### What to do when you can't support Dynamic Type %%