1

Trying to use systemBlueColor as the background of a button.

[myButton setBackgroundColor:[UIColor systemBlueColor]];

However, I get the error No known class method for selector 'systemBlueColor'

If I do a non-adaptive color like blueColor or greenColor it works fine. Any ideas?

Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Branch
  • 387
  • 5
  • 16
  • That's new to iOS 13. – rmaddy Jun 05 '19 at 20:32
  • Ah, didn't realize that. @rmaddy Any other way then to set the background to the system blue? (Objective-C) – Branch Jun 05 '19 at 20:33
  • Not prior to iOS 13. You have to hardcode the color you want. – rmaddy Jun 05 '19 at 20:34
  • @rmaddy not even if I somehow get the system color this way? https://stackoverflow.com/questions/19032940/how-can-i-get-the-ios-7-default-blue-color-programmatically – Branch Jun 05 '19 at 20:36
  • That might work. But if the `tintColor` is never set, and you get the blue by default, then `tintColor` is `nil` and it won't help for setting the background color. – rmaddy Jun 05 '19 at 20:37
  • Wait, https://developer.apple.com/documentation/uikit/uicolor/3173141-systembluecolor?language=objc says its in iOS 7+? @rmaddy – Branch Jun 05 '19 at 20:40

1 Answers1

3

systemBlueColor and the other systemXXXColor class properties (.systemBlue and other .systemXXX in Swift) were added in iOS 13 with Xcode 11. Oddly, the documentation for these colors state they are supported in iOS 7+.

I ran a test in one of my projects that supports iOS 9+ and in fact these colors can be used prior to iOS 13.

This means that those colors have actually been there since iOS 7 but they were private and now made public as of iOS 13. But in order to use them you need Xcode 11 and a Base SDK of iOS 13. Then these colors will be available with a Deployment Target back to iOS 7.

But note that iOS 13 also added several other colors referred to as "UI Element Colors". These include colors such as labelColor and systemBackgroundColor (.label and .systemBackground in Swift). These will only work with iOS 13 and later.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Perfect, thanks so much! Weird that they were private for so long! I wonder if that webpage I linked in my comment is new? – Branch Jun 05 '19 at 21:21