我们如何保持文本字段相对于屏幕大小的字体大小? [英] How can we keep a text field's font size relative to the screen size?
本文介绍了我们如何保持文本字段相对于屏幕大小的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本字段,我给它一个13像素的规则字体大小。
但是我希望字体大小相对于屏幕大小递增。
谢谢。
解决方案
在屏幕的尺寸。
let baseWidth:CGFloat = 320 //您要使用的屏幕宽度13pt
pre>
让fontSize = 13 *(UIScreen.main.size.width / baseWidth)
let font = UIFont(name:HelveticaNeue,size:fontSize)
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.
解决方案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)
这篇关于我们如何保持文本字段相对于屏幕大小的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文