问题
I have a text field and I have given it a regular font with 13 px in size.
But I want the font size to increment with respect to screen size.
Thanks.
回答1:
You can calculate the font size based on the screen's dimensions.
let baseWidth: CGFloat = 320 // the width of the screen where you want to use 13pt
let fontSize = 13 * (UIScreen.main.size.width / baseWidth)
let font = UIFont(name: "HelveticaNeue", size: fontSize)
回答2:
You can simply do this by checking, Automatically Adjusts Font
in the Attributes Inspector
来源:https://stackoverflow.com/questions/46176240/how-can-we-keep-a-text-fields-font-size-relative-to-the-screen-size