【发布时间】:2017-10-05 18:21:21
【问题描述】:
我正在尝试使用 UIAppearance 为我的应用创建主题。
假设我希望我的 UILabel 的所有文本都是橙色的。我写道:
UILabel.appearance(whenContainedInInstancesOf: [UIView.self]).textColor = .orange
但我意识到:
- 这适用于通过 Interface Builder 创建的每个
UILabel。 - 这不适用于以编程方式创建的任何
UILabel。它们默认显示为黑色
知道如何强制以编程方式创建的实例也变为橙色吗?
PS:我也试过:UILabel.appearance().textColor = .green 这不是我想要的,但它也不起作用。
【问题讨论】:
-
实际上
UILabel.appearance().textColor应该可以工作。什么时候调用这个方法?
标签: ios swift uikit uilabel uiappearance