I want to set the default text color for all UILabels in my app. I found this:
UILabel.appearance().textColor = UIColor.red
This works, but when I want to set some other color for a particular label in its storyboard, it cannot be done - all labels are still red.
Is it possible to define a default text color for all UILabels by setting it in storyboards and then change it for some UILabels ALSO in storyboards (not in code)? Or set the default color in code using the Appearance API and change it for some labels in storyboard?
SubClass you labels with CustomLabel.swift. You can set text color using IBDesignable
property named as txtColor
Below is the code working example
import UIKit
@IBDesignable class CustomLabel: UILabel {
@IBInspectable var txtColor: UIColor = UIColor.grayColor() {
didSet {
self.textColor = txtColor
}
}
func setup() {
self.textColor = txtColor
}
override func awakeFromNib() {
setup()
}
override func prepareForInterfaceBuilder() {
setup()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With