Created
July 27, 2016 22:20
-
-
Save adamrothman/d30fa3c6ebc015e33e143544272090ca to your computer and use it in GitHub Desktop.
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
extension UIColor { | |
convenience init(hex: UInt32, alpha: CGFloat = 1.0) { | |
self.init( | |
red: CGFloat((hex & 0xff0000) >> 16) / 256.0, | |
green: CGFloat((hex & 0x00ff00) >> 8) / 256.0, | |
blue: CGFloat(hex & 0x0000ff) / 256.0, | |
alpha: alpha | |
) | |
} | |
convenience init(hexString: String, alpha: CGFloat = 1.0) { | |
let scanner = NSScanner(string: hexString) | |
scanner.charactersToBeSkipped = NSCharacterSet(charactersInString: "#") | |
var hex: UInt32 = 0 | |
scanner.scanHexInt(&hex) | |
self.init(hex: hex, alpha: alpha) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment