Created
November 24, 2017 05:02
-
-
Save oalansari82/78794d7e96d262f236622437bb2b285f to your computer and use it in GitHub Desktop.
Create shortcut for RGB color and func that converts HEX to RGB
This file contains 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 { | |
static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor { | |
return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 1) | |
} | |
static func mainColor() -> UIColor { | |
return UIColor.rgb(red: 105, green: 26, blue: 64) | |
} | |
static func UIColorFromHex(rgbValue:UInt32, alpha:Double=1.0)->UIColor { | |
let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0 | |
let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0 | |
let blue = CGFloat(rgbValue & 0xFF)/256.0 | |
return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment