简体   繁体   English

如何在Swift中以编程方式访问系统颜色?

[英]How to access the system colors programmatically in Swift?

I'm trying to programmatically set the background color of an UIButton to the color UIColor.systemBlue , which I assume should be accessible according to the docs of UIColor and the color guidelines . 我正在尝试以编程方式将UIButton的背景颜色设置为颜色UIColor.systemBlue ,我认为应该可以根据UIColor的文档和颜色指南访问它 However, I can only access the regular colors such as .blue and .red . 但是,我只能访问常规色如.blue.red In the interface builder I can select systemBlue but not programmatically. 在界面构建器中,我可以选择systemBlue但不能以编程方式。

I'm using Xcode 10.3 and building for iOS 12.4. 我正在使用Xcode 10.3并为iOS 12.4构建。

EDIT : I've seen the question iOS 11.x system colors , but it doesn't make sense. 编辑 :我已经看到iOS 11.x系统颜色的问题,但它没有意义。 In the color guidelines it's clearly stated that the system color values shouldn't be hard-coded, but to use the API instead. 在颜色指南中,明确指出系统颜色值不应该是硬编码的,而是使用API​​代替。 And in the UIColor docs the system colors seem to be accessible as public class vars of UIColor. 在UIColor文档中,系统颜色似乎可以作为UIColor的公共类变量访问。

这些系统颜色仅在使用iOS 13 SDK时可用,这意味着您必须使用Xcode 11,而不是Xcode 10.3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM