The default text color for all UILabels

后端 未结 2 391
醉梦人生
醉梦人生 2021-02-05 18:07

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

2条回答
  •  囚心锁ツ
    2021-02-05 18:32

    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

提交回复
热议问题