Skip to content

Instantly share code, notes, and snippets.

@StevenMasini
Created December 12, 2017 09:54
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 StevenMasini/c0eca227576e74723d2469781832d834 to your computer and use it in GitHub Desktop.
Save StevenMasini/c0eca227576e74723d2469781832d834 to your computer and use it in GitHub Desktop.
extension UIColor {
/// Init a UIColor base on the color hexadecimal value
///
/// - Parameters:
/// - hex: Hexadecimal code of the color
/// - alpha: Alpha opacity, between 0 and 1
public convenience init(hex: UInt, alpha: CGFloat) {
self.init(
red: CGFloat((hex & 0xFF0000) >> 16) / 255.0,
green: CGFloat((hex & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(hex & 0x0000FF) / 255.0,
alpha: alpha
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment