Created
March 18, 2016 10:17
-
-
Save peiweichen/b23cf1ea699f7199cfdd to your computer and use it in GitHub Desktop.
UIColor Hex Extension in Swift
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 { | |
public convenience init(hex: UInt32, alpha: CGFloat = 1) { | |
let divisor = CGFloat(255) | |
let red = CGFloat((hex & 0xFF0000) >> 16) / divisor | |
let green = CGFloat((hex & 0x00FF00) >> 8) / divisor | |
let blue = CGFloat( hex & 0x0000FF ) / divisor | |
self.init(red: red, green: green, blue: blue, alpha: alpha) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment