ios - 使用 Swift 在整个应用程序中更改 UILabel 文本颜色

标签 ios swift uilabel

在 Swift 中有什么方法可以在整个应用程序中一次更改我的 UILabel 的文本颜色属性?我试过使用 appeareance 属性,但这对 UILabel textColor 不起作用。以相同方式工作的任何方式或任何库。

最佳答案

一种方法是使用颜色集

开始在您的 xcassets 目录中创建新集

enter image description here

...并根据需要命名

enter image description here

然后把你的颜色改成你需要的颜色

enter image description here

最后,将标签的颜色设置为 xcassets 目录中的颜色

enter image description here enter image description here

...或以编程方式

label.textColor = UIColor(named: "ColorForLabel")

现在,当您需要更改文本颜色时,只需更改此颜色集

的颜色即可

关于ios - 使用 Swift 在整个应用程序中更改 UILabel 文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54051412/

相关文章:

ios - Firebase observeSingleEvent 保留在内存中

ios - 具有独立视频和音频 url 的 AVAsset (iOS)

swift - 使用类型调用 swift 类的初始值设定项

swift - 如何使 UILabel 在未跟踪图像时出现在屏幕上,并在跟踪图像时消失

ios - 从服务器接收到数据后,如何在我的应用程序的 View Controller 标签中显示数据(从静态硬编码值更新)

ios - iOS 的 codename1.ext.codescan cn1lib 有问题

xcode - 全屏退出后模态 NSWindow 消失

iOS:大型 UIAlertController ActionSheet 在滚动时弹跳并且不显示行分隔符

ios - 我有一个仅当我的 UITableView 为空时才可见的 UILabel。如何在 Swift 中将该标签的文本居中?

ios - 在 Objective-C 中反转字符串数组