【问题标题】:Using systemBlueColor as a button background使用 systemBlueColor 作为按钮背景
【发布时间】:2019-06-05 20:31:27
【问题描述】:

尝试使用systemBlueColor 作为按钮的背景。

[myButton setBackgroundColor:[UIColor systemBlueColor]];

但是,我收到错误 No known class method for selector 'systemBlueColor'

如果我使用 blueColor 或 greenColor 等非自适应颜色,则效果很好。有什么想法吗?

谢谢!

【问题讨论】:

  • 这是 iOS 13 的新功能。
  • 啊,没想到。 @rmaddy还有其他方法可以将背景设置为系统蓝色吗? (目标-C)
  • 不是在 iOS 13 之前。你必须硬编码你想要的颜色。
  • @rmaddy 即使我以这种方式获得系统颜色也不行? stackoverflow.com/questions/19032940/…
  • 这可能行得通。但是如果tintColor从未设置过,而你默认得到蓝色,那么tintColor就是nil,它对设置背景颜色没有帮助。

标签: ios uicolor


【解决方案1】:

systemBlueColor 和其他 systemXXXColor 类属性(.systemBlue 和其他 .systemXXX 在 Swift 中)是在带有 Xcode 11 的 iOS 13 中添加的。奇怪的是,这些颜色的文档表明它们在 iOS 7+ 中受支持.

我在一个支持 iOS 9+ 的项目中进行了测试,实际上这些颜色可以在 iOS 13 之前使用。

这意味着这些颜色实际上从 iOS 7 开始就存在,但它们是私有的,现在从 iOS 13 开始公开。但要使用它们,您需要 Xcode 11 和 iOS 13 的 Base SDK。然后这些颜色将可通过部署目标回到 iOS 7。

但请注意,iOS 13 还添加了其他几种颜色,称为“UI 元素颜色”。其中包括诸如labelColorsystemBackgroundColor 之类的颜色(在Swift 中为.label.systemBackground)。这些仅适用于 iOS 13 及更高版本。

【讨论】:

  • 完美,非常感谢!奇怪的是他们这么长时间都是私人的!我想知道我在评论中链接的那个网页是不是新网页?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 2012-03-06
  • 1970-01-01
  • 1970-01-01
  • 2014-09-25
  • 2011-12-29
  • 1970-01-01
相关资源
最近更新 更多