[英]Can't set text color of UILabel implemented as custom view to UIBarButtonItem
I'd like to implement a custom label in the toolbar, but I can't change its text color:我想在工具栏中实现自定义 label ,但我无法更改其文本颜色:
// MARK: - Initialize the status label (toolbar)
func initStatusLabel() {
statusLabel.layer.borderColor = UIColor.red.cgColor;
statusLabel.layer.borderWidth = 1;
statusLabel.layer.masksToBounds = true;
statusLabel.layer.cornerRadius = 8;
statusLabel.font = statusLabel.font.withSize(12);
statusLabel.leftTextInset = 8;
statusLabel.rightTextInset = 8;
statusLabel.topTextInset = 8;
statusLabel.bottomTextInset = 8;
statusLabel.text = "Hello World";
statusLabel.adjustsFontSizeToFitWidth = true;
statusLabel.backgroundColor = .systemRed;
statusLabel.textColor = .white;
statusLabel.sizeToFit();
}
The white color will be ignored for some reasons:由于某些原因,白色将被忽略:
Any ideas?有任何想法吗?
Try setting tint color for UILable, or you can also use UIButton尝试为 UILable 设置色调颜色,或者您也可以使用 UIButton
let rightBarButtonItem = UIBarButtonItem(title: "Some text", style: .plain, target: self, action: #selector(someAction))
rightBarButtonItem.tintColor = UIColor.myMusicPurple
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.