Created
June 20, 2019 13:55
-
-
Save ppm/45823763fe88548dce990c56b3b3c28a to your computer and use it in GitHub Desktop.
An UIColor extension to gracefully adapt iOS 13 system colors: It returns the new system color if available, otherwise a color you specified. Supports Objective-C.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIColor { | |
@objc | |
class func systemIndigo(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemIndigo | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func systemGray2(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray2 | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func systemGray3(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray3 | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func systemGray4(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray4 | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func systemGray5(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray5 | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func systemGray6(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray6 | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func label(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .label | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func secondaryLabel(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .secondaryLabel | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func tertiaryLabel(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .tertiaryLabel | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func quaternaryLabel(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .quaternaryLabel | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func link(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .link | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func placeholderText(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .placeholderText | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func separator(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .separator | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func opaqueSeparator(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .opaqueSeparator | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func systemBackground(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemBackground | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func secondarySystemBackground(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .secondarySystemBackground | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func tertiarySystemBackground(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .tertiarySystemBackground | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func systemGroupedBackground(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemGroupedBackground | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func secondarySystemGroupedBackground(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .secondarySystemGroupedBackground | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func tertiarySystemGroupedBackground(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .tertiarySystemGroupedBackground | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func systemFill(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .systemFill | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func secondarySystemFill(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .secondarySystemFill | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func tertiarySystemFill(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .tertiarySystemFill | |
} else { | |
return substitute | |
} | |
} | |
@objc | |
class func quaternarySystemFill(or substitute: UIColor) -> UIColor { | |
if #available(iOS 13, *) { | |
return .quaternarySystemFill | |
} else { | |
return substitute | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment