Change UIAppearance of default UILabels only

I'm building an app with a theme switcher and I'd like to use Appearance to switch the textColor of UILabels that have the default color (black -> white).

I assumed this would be possible and created subclasses for non-default labels, so I simply have to target UILabels with either no subclass or that kept the default color.

When I change the appearance with the following :

UILabel.appearance().textColor = UIColor.white

Every single Label, including subclasses and system labels become white, UIAppearance overriding control-level customization. I feel like it makes sense for UIAppearance to be the default state and for any customization to be applied on top of it.

Would there be any way to use UIAppearance to solve this? Or do I have to manually edit every label I have to add a subclass and a custom property?

Thanks for your help!


The only way I found to overcome this problem is to make the textColor variable read only. But it works:

UILabel.appearance().textColor = UIColor.orange

And the custom class:

class MyLabel: UILabel {
    override var textColor: UIColor! {
        get { return UIColor.blue }
        set {}
    }
}
链接地址: http://www.djcxy.com/p/96246.html

上一篇: 二维数组的UIButtons不工作(目标

下一篇: 仅更改默认UILabels的UIA外观