How can we keep a text field's font size relative to the screen size?

限于喜欢 提交于 2019-12-02 01:25:09

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)

You can simply do this by checking, Automatically Adjusts Font in the Attributes Inspector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!