Skip to content

Instantly share code, notes, and snippets.

@peiweichen
Created March 18, 2016 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peiweichen/b23cf1ea699f7199cfdd to your computer and use it in GitHub Desktop.
Save peiweichen/b23cf1ea699f7199cfdd to your computer and use it in GitHub Desktop.
UIColor Hex Extension in Swift
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