Search code examples
swiftswiftuiuikitdynamic-type-feature

iOS Swift how to detect Dynamic Type Sizes with customer Font


I have already finished dynamic type customer font set in my App through this article:

https://www.hackingwithswift.com/quick-start/swiftui/how-to-use-dynamic-type-with-a-custom-font

but i got new requirements from designer:

enter image description here

as you can see we have xSmall/Small/Medium/Large/xLarge/xxLarge/xxxLarge 7 totally font sizes in Apple HIG.

designer give the following rules:

xSmall -> same with app current default size

Small -> same with app current default size

Medium -> same with app current default size

Large -> Default size

xLarge -> Default size + 1pt

xxLarge -> Default size + 2pt

xxxLarge -> Default size + 3pt

my question is how to detect App system font set to small or xLarge so that i can give some compute value? how to approach the new requirements?


Solution

  • Watch for the trait collection to change and read the preferredContentSizeCategory. If it has changed, mess with the interface as desired.