【问题标题】:Some UI elements don't acquire UIAppearance traits一些 UI 元素不获取 UIAppearance 特征
【发布时间】:2012-04-12 15:08:56
【问题描述】:

我正在尝试使用 UIAppearance 在我的 iOS 应用程序中获得统一的颜色主题。例如我尝试将所有UILabel对象的文本颜色设置如下:

[[UILabel appearance] setTextColor:[UIColor colorWithRed:0.7 green:0.07 blue:0.12 alpha:1]];

这适用于我的故事板/XIB 中静态定义的所有对象。但是,有时我需要在视图中动态创建 UILabel。在这些情况下,不使用 UIAppearance。而是使用默认文本颜色(黑色)。

除了采用旧的“手动设置每个元素”方法之外,有没有人遇到过这个问题/找到了解决方法?

【问题讨论】:

  • 这真的很奇怪。我注意到,如果我创建动态标签并然后设置它们的外观,它会起作用......但我认为这对大多数情况没有帮助。
  • 我确实试过了,但它也对我不起作用。到目前为止,我只是创建了标签,然后调用myLabel.textColor = [[UILabel appearance] textColor] 将其设置为当前颜色的 UIAppearance 颜色,但似乎错过了 UIAppearance 的重点。

标签: ios ios5 uiview uilabel


【解决方案1】:

似乎不是所有的类都支持 UIAppearance 而 UILabel 不是其中之一。

查看此问题以获取更多信息: UIAppearance not taking effect on UILabels created programatically

以下是支持 UIAppearance 的类的列表: http://blog.mosheberman.com/list-of-classes-that-support-uiappearance-in-ios-5/

【讨论】:

  • 但不知何故 UILabel.appearance 编译。感谢苹果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-28
  • 2016-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多