Search code examples
iosswiftuicolor

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. However, I can only access the regular colors such as .blue and .red. In the interface builder I can select systemBlue but not programmatically.

I'm using Xcode 10.3 and building for iOS 12.4.

EDIT: I've seen the question iOS 11.x system colors, but it doesn't make sense. In the color guidelines it's clearly stated that the system color values shouldn't be hard-coded, but to use the API instead. And in the UIColor docs the system colors seem to be accessible as public class vars of UIColor.


Solution

  • These system colors are only available when using the iOS 13 SDK, meaning you must use Xcode 11, not Xcode 10.3.