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 whe
There is also an alternative to what Muhammad suggested. The alternative is to use the UIAppearance proxy, but specify the classes where it would be applied to.
In that case, you would use it like this:
UILabel.appearanceWhenContainedInInstancesOfClasses([MyViewController.self, MyotherViewController.self]).textColor = UIColor.red
The above though, would only allow you to set the textColor your self in some classes. in those where the proxy is set to be enabled, you won't be able to set the text color.
It's up to you to choose which approach is better for your case
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()
}
}