如何在Swift中更改UILabel的字体大小? [英] How do I change the font size of a UILabel in Swift?
本文介绍了如何在Swift中更改UILabel的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
label.font.pointSize
是只读的,所以我不确定如何更改它.
label.font.pointSize
is read-only, so I'm not sure how to change it.
推荐答案
您可以这样做:
label.font = UIFont(name: label.font.fontName, size: 20)
或者像这样:
label.font = label.font.withSize(20)
这将使用相同的字体.当然,您想要的大小可以是20.
This will use the same font. 20 can be whatever size you want of course.
注意:后一个选项会将当前字体粗细覆盖为 regular
,因此,如果要保留字体粗细,请使用第一个选项.
Note: The latter option will overwrite the current font weight to regular
so if you want to preserve the font weight use the first option.
迅速3更新:
label.font = label.font.withSize(20)
迅速4更新:
label.font = label.font.withSize(20)
或
label.font = UIFont(name:"fontname", size: 20.0)
,如果您使用系统字体
label.font = UIFont.systemFont(ofSize: 20.0)
label.font = UIFont.boldSystemFont(ofSize: 20.0)
label.font = UIFont.italicSystemFont(ofSize: 20.0)
这篇关于如何在Swift中更改UILabel的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文