I am very new to swift and trying to create an extension of UIColor class as
extension UIColor{
func getCustomBlueColor() -> UIColor {
retur
Swift 3, Swift 4, Swift 5:
extension UIColor {
static let myBlue = UIColor(red:0.043, green:0.576 ,blue:0.588, alpha:1.00)
}
Use:
btnShare.setTitleColor(.myBlue, for: .normal)
Or
self.view.backgroundColor = .myBlue
If you use Color Set in *.xcassets (iOS11+). For example, you have a color with the name «appBlue». Then:
extension UIColor {
private static func getColorForName(_ colorName: String) -> UIColor {
UIColor(named: colorName) ?? UIColor.red
}
static var appBlue: UIColor {
self.getColorForName("appBlue")
}
}
Use:
self.view.backgroundColor = .appBlue