[英]Can't set text color of UILabel implemented as custom view to UIBarButtonItem
我想在工具欄中實現自定義 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();
}
由於某些原因,白色將被忽略:
有任何想法嗎?
嘗試為 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.