WWDC23 SALE: Save 50% on all my Swift books and bundles! >>

How to specify the Dynamic Type sizes a view supports

Paul Hudson    @twostraws   

Updated for Xcode 14.2

SwiftUI’s automatic support of Dynamic Type means our views are free to grow and shrink according to the user’s preference. However, sometimes you might need to place limits on just how far your user interface is able to adjust, and for that we have the dynamicTypeSize() modifier.

This can used with a fixed value, meaning that your view will ignore all Dynamic Type sizes:

Text("This will stay small")

This is helpful if you want to force a particular kind of preview, for example.

You can also specify ranges, such as this one that allows any size up to and including the large size:

Text("This won't go above large")

If you enable Xcode’s environment overrides, you can see how each of these variants adjust:

VStack {
    Text("This will stay small")
    Text("This won't go above large")
    Text("This will scale within a range")
    Text("This will scale to any size")

Remember, many users rely on larger Dynamic Type sizes in order to use your app, and a surprisingly large number of users use it to cram more information onto their screen. So, try to avoid limiting the sizes you support to those times when it’s really necessary.

Save 50% in my WWDC23 sale.

SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Similar solutions…

Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 5.0/5

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.