Skip to content

Instantly share code, notes, and snippets.

@idrisr
Created July 25, 2016 19:27
Show Gist options
  • Save idrisr/08e42cf397d9d26f5a060996ed6f1d9d to your computer and use it in GitHub Desktop.
Save idrisr/08e42cf397d9d26f5a060996ed6f1d9d to your computer and use it in GitHub Desktop.
Shift then mask
public convenience init (_ rgbHex: UInt, alpha: CGFloat = 1.0) {
let rawRed = Double((rgbHex >> 16) & 0xFF) / 255.0
let rawGreen = Double((rgbHex >> 8) & 0xFF) / 255.0
let rawBlue = Double(rgbHex & 0xFF) / 255.0
self.init(red: CGFloat(rawRed), green: CGFloat(rawGreen), blue: CGFloat(rawBlue), alpha: alpha)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment