Implementing text size picker in app in SwiftUI

65 Views Asked by At

How can I implement a text size picker in my app which apply the text size to all parts of the app (i.e. NavigationBar, TabBar, etc)

I understand now in the latest iOS there is per-app settings (in the system a11y menu) but I couldn't locate any API to allow to deploy the selection in-app.

Thanks!

I'm looking to implement something like what Ivory, Apollo, TweetBot have in their app.

1

There are 1 best solutions below

0
On

You can pass in a dynamic type size to any view using the .dynamicTypeSize environment value, a read-write property that allows you to override the user's chosen type size, e.g.

  ContentView()
    .environment(\.dynamicTypeSize, myTypeSize)

For this to work, you'd need to make sure myTypeSize is a DynamicTypeSize enum.

A note of caution: doing this overrides values that your users may have very good reason for setting themselves within their phone or iPad settings, and so using it to provide in-app UI changes may not be the best idea. It could make accessibility worse for your users, rather than better.

Personal opinion: I'd say that the time you spend working on building your own dynamic type size system would be better spent ensuring your existing views work with whatever system setting has been chosen. Adjusting your layouts to work in whatever situation, using SwiftUI tools including @ScaledMetric, ViewThatFits and more, will be more beneficial in the long run.