I’d like to implement a custom label in the toolbar, but I can’t change its text color:
// 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?
2
Answers
I found the reason. Obviously you can't change the color if the bar buttom item is not enabled in the storyboard:
Try setting tint color for UILable, or you can also use UIButton