使用 Swift 在整个应用程序中更改 UILabel 的 textColor
问题描述:
在 Swift 中有什么方法可以在整个应用程序中一次性更改 UILabel 的文本颜色属性吗?我试过使用外观属性,但这不适用于 UILabel textColor.任何方式或任何可以使用相同方法的库.
Is there any way in Swift i can change my UILabel's text color property at once in whole app? I've tried using appeareance property but that doesn't work for UILabel textColor. Any way or any library that works on the same.
答
一种方法是使用 Color Set.
首先在您的 xcassets 目录中创建新集
Start with creating new set in your xcassets catalog
...并按照您想要的方式命名
... and name it how you want to
然后将颜色更改为您需要的颜色
Then change your color to color that you need
最后,将标签的颜色设置为 xcassets 目录中的颜色
Finally, set color of your label as this color from xcassets catalog
... 或以编程方式
label.textColor = UIColor(named: "ColorForLabel")
现在当您需要更改文本颜色时,只需更改此颜色集