使用UILabel的字体和纯文本而不是使用NSAttributedString和整个文本都具有字体的性能优势。
换句话说,两者之间有什么区别
class Label1: UILabel {
func display(text: String, with font: UIFont) {
self.font = font
self.text = text
}
}
和
class Label2: UILabel {
func display(text: String, with font: UIFont) {
attributedText = NSAttributedString(
string: text,
attributes: [
NSAttributedString.Key.font: font,
]
)
}
}