Last active
November 22, 2017 07:20
-
-
Save khawajafarooq/0477974c41019a7e3cf2aada50d6c6bf to your computer and use it in GitHub Desktop.
Creating app themes with swift enum
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 AppColor { | |
case blue | |
case gray | |
case graySeparator | |
var rgba: [CGFloat] { | |
switch self { | |
case .blue: return [118.0 / 255.0, 214.0 / 255.0, 255.0 / 255.0, 1.0] | |
case .gray: return [235.0 / 255.0, 235.0 / 255.0, 235.0 / 255.0, 1.0] | |
case .graySeparator: return [169.0 / 255.0, 169.0 / 255.0, 169.0 / 255.0, 1.0] | |
} | |
} | |
var r: CGFloat { return self.rgba[0] } | |
var g: CGFloat { return self.rgba[1] } | |
var b: CGFloat { return self.rgba[2] } | |
var a: CGFloat { return self.rgba[3] } | |
} | |
// MARK: - UIColor extension | |
extension UIColor { | |
convenience init(appColor: AppColor) { | |
self.init(red: appColor.r, green: appColor.g, blue: appColor.b, alpha: appColor.a) | |
} | |
} |
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
func visualSetup() { | |
let progressControl = UIProgressView(progressViewStyle: .default) | |
progressControl.progressTintColor = UIColor(appColor: .blue) | |
progressControl.trackTintColor = UIColor(appColor: .gray) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment