我正在尝试创建一个自定义 UILabel,其中文本颜色为红色。这是我尝试过的,但这些都不起作用:
class CustomLabel: UILabel {
override func awakeFromNib() {
UILabel.appearance().textColor = UIColor.blue
textColor = UIColor.blue
}
}
Run Code Online (Sandbox Code Playgroud)
您缺少另一个案例,Label可以使用或不使用笔尖创建一个案例。尝试这个:
class MyCustomLabel: UILabel {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
// This will call `awakeFromNib` in your code
setup()
}
private func setup() {
self.textColor = .red
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2325 次 |
| 最近记录: |