Last active
August 18, 2021 19:09
-
-
Save verebes1/f693398df2b3b9424b31a935b8b3370c to your computer and use it in GitHub Desktop.
Using UIColors from iOS13 with backward compatibility to previous iOS versions.
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 | |
public enum ColorSupport { | |
public static var label: UIColor { | |
if #available(iOS 13, *) { | |
return .label | |
} | |
return UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0) | |
} | |
public static var secondaryLabel: UIColor { | |
if #available(iOS 13, *) { | |
return .secondaryLabel | |
} | |
return UIColor(red: 60.0 / 255.0, green: 60.0 / 255.0, blue: 67.0 / 255.0, alpha: 0.6) | |
} | |
public static var tertiaryLabel: UIColor { | |
if #available(iOS 13, *) { | |
return .tertiaryLabel | |
} | |
return UIColor(red: 60.0 / 255.0, green: 60.0 / 255.0, blue: 67.0 / 255.0, alpha: 0.3) | |
} | |
public static var quaternaryLabel: UIColor { | |
if #available(iOS 13, *) { | |
return .quaternaryLabel | |
} | |
return UIColor(red: 60.0 / 255.0, green: 60.0 / 255.0, blue: 67.0 / 255.0, alpha: 0.18) | |
} | |
public static var systemFill: UIColor { | |
if #available(iOS 13, *) { | |
return .systemFill | |
} | |
return UIColor(red: 120.0 / 255.0, green: 120.0 / 255.0, blue: 128.0 / 255.0, alpha: 0.2) | |
} | |
public static var secondarySystemFill: UIColor { | |
if #available(iOS 13, *) { | |
return .secondarySystemFill | |
} | |
return UIColor(red: 120.0 / 255.0, green: 120.0 / 255.0, blue: 128.0 / 255.0, alpha: 0.16) | |
} | |
public static var tertiarySystemFill: UIColor { | |
if #available(iOS 13, *) { | |
return .tertiarySystemFill | |
} | |
return UIColor(red: 118.0 / 255.0, green: 118.0 / 255.0, blue: 128.0 / 255.0, alpha: 0.12) | |
} | |
public static var quaternarySystemFill: UIColor { | |
if #available(iOS 13, *) { | |
return .quaternarySystemFill | |
} | |
return UIColor(red: 116.0 / 255.0, green: 116.0 / 255.0, blue: 128.0 / 255.0, alpha: 0.08) | |
} | |
public static var placeholderText: UIColor { | |
if #available(iOS 13, *) { | |
return .placeholderText | |
} | |
return UIColor(red: 60.0 / 255.0, green: 60.0 / 255.0, blue: 67.0 / 255.0, alpha: 0.3) | |
} | |
public static var systemBackground: UIColor { | |
if #available(iOS 13, *) { | |
return .systemBackground | |
} | |
return UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) | |
} | |
public static var secondarySystemBackground: UIColor { | |
if #available(iOS 13, *) { | |
return .secondarySystemBackground | |
} | |
return UIColor(red: 242.0 / 255.0, green: 242.0 / 255.0, blue: 247.0 / 255.0, alpha: 1.0) | |
} | |
public static var tertiarySystemBackground: UIColor { | |
if #available(iOS 13, *) { | |
return .tertiarySystemBackground | |
} | |
return UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) | |
} | |
public static var systemGroupedBackground: UIColor { | |
if #available(iOS 13, *) { | |
return .systemGroupedBackground | |
} | |
return UIColor(red: 242.0 / 255.0, green: 242.0 / 255, blue: 247.0 / 255.0, alpha: 1.0) | |
} | |
public static var secondarySystemGroupedBackground: UIColor { | |
if #available(iOS 13, *) { | |
return .secondarySystemGroupedBackground | |
} | |
return UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) | |
} | |
public static var tertiarySystemGroupedBackground: UIColor { | |
if #available(iOS 13, *) { | |
return .tertiarySystemGroupedBackground | |
} | |
return UIColor(red: 242.0 / 255.0, green: 242.0 / 255, blue: 247.0 / 255.0, alpha: 1.0) | |
} | |
public static var separator: UIColor { | |
if #available(iOS 13, *) { | |
return .separator | |
} | |
return UIColor(red: 60.0 / 255.0, green: 60.0 / 255.0, blue: 67.0 / 255.0, alpha: 0.29) | |
} | |
public static var opaqueSeparator: UIColor { | |
if #available(iOS 13, *) { | |
return .opaqueSeparator | |
} | |
return UIColor(red: 198.0 / 255.0, green: 198.0 / 255.0, blue: 200.0 / 255.0, alpha: 1.0) | |
} | |
public static var link: UIColor { | |
if #available(iOS 13, *) { | |
return .link | |
} | |
return UIColor(red: 0.0, green: 122.0 / 255.0, blue: 1.0, alpha: 1.0) | |
} | |
public static var darkText: UIColor { | |
if #available(iOS 13, *) { | |
return .link | |
} | |
return UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0) | |
} | |
public static var lightText: UIColor { | |
if #available(iOS 13, *) { | |
return .link | |
} | |
return UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.6) | |
} | |
public static var systemBlue: UIColor { | |
if #available(iOS 13, *) { | |
return .systemBlue | |
} | |
return UIColor(red: 0.0, green: 122.0 / 255.0, blue: 1.0, alpha: 1.0) | |
} | |
public static var systemGreen: UIColor { | |
if #available(iOS 13, *) { | |
return .systemGreen | |
} | |
return UIColor(red: 52.0 / 255.0, green: 199.0 / 255.0, blue: 89.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemIndigo: UIColor { | |
if #available(iOS 13, *) { | |
return .systemIndigo | |
} | |
return UIColor(red: 88.0 / 255.0, green: 86.0 / 255.0, blue: 214.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemOrange: UIColor { | |
if #available(iOS 13, *) { | |
return .systemOrange | |
} | |
return UIColor(red: 1.0, green: 149.0 / 255.0, blue: 0.0, alpha: 1.0) | |
} | |
public static var systemPink: UIColor { | |
if #available(iOS 13, *) { | |
return .systemPink | |
} | |
return UIColor(red: 1.0, green: 45.0 / 255.0, blue: 85.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemPurple: UIColor { | |
if #available(iOS 13, *) { | |
return .systemPurple | |
} | |
return UIColor(red: 175.0 / 255.0, green: 82.0 / 255.0, blue: 222.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemRed: UIColor { | |
if #available(iOS 13, *) { | |
return .systemRed | |
} | |
return UIColor(red: 1.0, green: 59.0 / 255.0, blue: 48.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemTeal: UIColor { | |
if #available(iOS 13, *) { | |
return .systemTeal | |
} | |
return UIColor(red: 90.0 / 255.0, green: 200.0 / 255.0, blue: 250.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemYellow: UIColor { | |
if #available(iOS 13, *) { | |
return .systemYellow | |
} | |
return UIColor(red: 1.0, green: 204.0 / 255.0, blue: 0.0, alpha: 1.0) | |
} | |
public static var systemGray: UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray | |
} | |
return UIColor(red: 142.0 / 255.0, green: 142.0 / 255.0, blue: 147.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemGray2: UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray2 | |
} | |
return UIColor(red: 174.0 / 255.0, green: 174.0 / 255.0, blue: 178.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemGray3: UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray3 | |
} | |
return UIColor(red: 199.0 / 255.0, green: 199.0 / 255.0, blue: 204.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemGray4: UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray4 | |
} | |
return UIColor(red: 209.0 / 255.0, green: 209.0 / 255.0, blue: 214.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemGray5: UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray5 | |
} | |
return UIColor(red: 229.0 / 255.0, green: 229.0 / 255.0, blue: 234.0 / 255.0, alpha: 1.0) | |
} | |
public static var systemGray6: UIColor { | |
if #available(iOS 13, *) { | |
return .systemGray6 | |
} | |
return UIColor(red: 242.0 / 255.0, green: 242.0 / 255.0, blue: 247.0 / 255.0, alpha: 1.0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use simply add this to your project and use instead of UIColor
For example:
replace
UIColor.systemRed
with
ColorSupport.systemRed