问题
I am new to IOS development and working on an application whose font size doesn't get affected by a change in the font size of the phone, which is set by the user, while the font size of other apps installed on my phone gets change. For example if changed from General->Accessibility->Large Text (On) it impacts all the application except mine.
Now as per the requirement of our users it should change the size of our application as well, does anybody know how to enable our disable this font scaling ?
I have searched a lot but could only found solutions for react and flutter only.
回答1:
On each textfield/uilabel there is a flag on the storyboard under the attributes inspector called "Dynamic Type: Automatically Adjusts Font", that needs to be checked.
Also, for the font you need to choose a dynamic font type, in the storyboard these fonts show up under the "Text Styles" section when choosing a font size. When you choose one of those fonts you won't be able to provide a font size as they will pull the fonts dynamically.
In this screenshot I've selected "Caption 1" and checked "Automatically Adjusts Font" which will allow the font to adjust per user settings.
If you are using these settings you should also be using auto-layout wherever possible so the text does not get cut-off on larger sizes.
These settings need to be changed on each uilabel/textfield in your app.
If you are doing this programmatically you need to set the font to a preferred font:
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .body)
来源:https://stackoverflow.com/questions/55971292/enable-disable-font-scaling-impact-by-ios-on-my-application