【发布时间】:2019-12-19 21:32:29
【问题描述】:
我想问一下,有什么方法可以通过单个代码更改标签的所有字体,大小? 就像应用程序内的动态类型一样。 例如:Android 已支持 XML 文件 (dimens)
谢谢!
【问题讨论】:
我想问一下,有什么方法可以通过单个代码更改标签的所有字体,大小? 就像应用程序内的动态类型一样。 例如:Android 已支持 XML 文件 (dimens)
谢谢!
【问题讨论】:
有几种方法可以实现这一目标
UILabels 提供相同的样式:extension UILabel {
@nonobjc
convenience init() {
self.init(frame: .zero)
self.font = UIFont.systemFont(ofSize: 12, weight: UIFontWeightThin)
//... here goes other changes
}
}
您每次都需要使用方便的 init。
UILabel:class CustomLabel: UILabel {
override init(frame: CGRect) {
super.init(frame: frame)
self.font = UIFont.systemFont(ofSize: 12, weight: UIFontWeightThin)
//... here goes other changes
}
required init?(coder: NSCoder) {
super.init(coder: coder)
self.font = UIFont.systemFont(ofSize: 12, weight: UIFontWeightThin)
//... here goes other changes
}
}
UILabel 的不同样式。【讨论】: