Last active
February 21, 2021 05:13
-
-
Save hoppsen/f3cbe2dd51ad40cfe80609b2e9bebada to your computer and use it in GitHub Desktop.
Introducing system color wrappers to benefit from the new system colors under iOS 12 and below.
This file contains hidden or 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
// | |
// UIColor+SystemColors.swift | |
// | |
// https://gist.github.com/hoppsen/f3cbe2dd51ad40cfe80609b2e9bebada | |
// | |
// More about Apple's System Colors can be found here: | |
// https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/ | |
import UIKit | |
// MARK: - Update existing colors to iOS 13 values | |
extension UIColor { | |
static let systemGreenWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemGreen | |
} else { | |
return UIColor(red: 52.0 / 255.0, green: 199.0 / 255.0, blue: 89.0 / 255.0, alpha: 1.0) | |
} | |
}() | |
static let systemPurpleWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemPurple | |
} else { | |
return UIColor(red: 175.0 / 255.0, green: 82.0 / 255.0, blue: 222.0 / 255.0, alpha: 1.0) | |
} | |
}() | |
} | |
// MARK: - Make new colors available for iOS 12 and below | |
extension UIColor { | |
static let systemIndigoWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemIndigo | |
} else { | |
return UIColor(red: 88.0 / 255.0, green: 86.0 / 255.0, blue: 214.0 / 255.0, alpha: 1.0) | |
} | |
}() | |
static let systemGray2Wrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemGray2 | |
} else { | |
return UIColor(red: 174.0 / 255.0, green: 174.0 / 255.0, blue: 178.0 / 255.0, alpha: 1.0) | |
} | |
}() | |
static let systemGray3Wrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemGray3 | |
} else { | |
return UIColor(red: 199.0 / 255.0, green: 199.0 / 255.0, blue: 204.0 / 255.0, alpha: 1.0) | |
} | |
}() | |
static let systemGray4Wrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemGray4 | |
} else { | |
return UIColor(red: 209.0 / 255.0, green: 209.0 / 255.0, blue: 214.0 / 255.0, alpha: 1.0) | |
} | |
}() | |
static let systemGray5Wrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemGray5 | |
} else { | |
return UIColor(red: 229.0 / 255.0, green: 229.0 / 255.0, blue: 234.0 / 255.0, alpha: 1.0) | |
} | |
}() | |
static let systemGray6Wrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemGray6 | |
} else { | |
return UIColor(red: 242.0 / 255.0, green: 242.0 / 255.0, blue: 247.0 / 255.0, alpha: 1.0) | |
} | |
}() | |
static let labelWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .label | |
} else { | |
return UIColor(white: 0.0, alpha: 1.0) | |
} | |
}() | |
static let secondaryLabelWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .secondaryLabel | |
} else { | |
return UIColor(red: 0.235, green: 0.235, blue: 0.263, alpha: 0.6) | |
} | |
}() | |
static let tertiaryLabelWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .tertiaryLabel | |
} else { | |
return UIColor(red: 0.235, green: 0.235, blue: 0.263, alpha: 0.3) | |
} | |
}() | |
static let quaternaryLabelWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .quaternaryLabel | |
} else { | |
return UIColor(red: 0.235, green: 0.235, blue: 0.263, alpha: 0.18) | |
} | |
}() | |
static let linkWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .link | |
} else { | |
return UIColor(red: 0.0, green: 0.478, blue: 1.0, alpha: 1.0) | |
} | |
}() | |
static let placeholderTextWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .placeholderText | |
} else { | |
return UIColor(red: 0.235, green: 0.235, blue: 0.263, alpha: 0.3) | |
} | |
}() | |
static let separatorWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .separator | |
} else { | |
return UIColor(red: 0.235, green: 0.235, blue: 0.263, alpha: 0.29) | |
} | |
}() | |
static let opaqueSeparatorWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .opaqueSeparator | |
} else { | |
return UIColor(red: 0.776, green: 0.776, blue: 0.784, alpha: 1.0) | |
} | |
}() | |
static let systemBackgroundWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemBackground | |
} else { | |
return UIColor(white: 1.0, alpha: 1.0) | |
} | |
}() | |
static let secondarySystemBackgroundWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .secondarySystemBackground | |
} else { | |
return UIColor(red: 0.949, green: 0.949, blue: 0.969, alpha: 1.0) | |
} | |
}() | |
static let tertiarySystemBackgroundWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .tertiarySystemBackground | |
} else { | |
return UIColor(white: 1.0, alpha: 1.0) | |
} | |
}() | |
static let systemGroupedBackgroundWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemGroupedBackground | |
} else { | |
return UIColor(red: 0.949, green: 0.949, blue: 0.969, alpha: 1.0) | |
} | |
}() | |
static let secondarySystemGroupedBackgroundWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .secondarySystemGroupedBackground | |
} else { | |
return UIColor(white: 1.0, alpha: 1.0) | |
} | |
}() | |
static let tertiarySystemGroupedBackgroundWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .tertiarySystemGroupedBackground | |
} else { | |
return UIColor(red: 0.949, green: 0.949, blue: 0.969, alpha: 1.0) | |
} | |
}() | |
static let systemFillWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .systemFill | |
} else { | |
return UIColor(red: 0.471, green: 0.471, blue: 0.502, alpha: 0.2) | |
} | |
}() | |
static let secondarySystemFillWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .secondarySystemFill | |
} else { | |
return UIColor(red: 0.471, green: 0.471, blue: 0.502, alpha: 0.16) | |
} | |
}() | |
static let tertiarySystemFillWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .tertiarySystemFill | |
} else { | |
return UIColor(red: 0.463, green: 0.463, blue: 0.502, alpha: 0.12) | |
} | |
}() | |
static let quaternarySystemFillWrapper: UIColor = { | |
if #available(iOS 13.0, *) { | |
return .quaternarySystemFill | |
} else { | |
return UIColor(red: 0.455, green: 0.455, blue: 0.502, alpha: 0.08) | |
} | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment