Guest User

Untitled

a guest
May 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. extension UIColor {
  2.  
  3. convenience init(hex: String) {
  4.  
  5. let trimmedString = hex.replacingOccurrences(of: "#", with: "")
  6.  
  7. var uint32Value: UInt32 = 0
  8. Scanner(string: trimmedString).scanHexInt32(&uint32Value)
  9.  
  10. let intValue = Int(uint32Value)
  11. self.init(hex: intValue)
  12. }
  13.  
  14. convenience init(hex: Int) {
  15.  
  16. let r = CGFloat((hex >> 16) & 0xff) / 255
  17. let g = CGFloat((hex >> 08) & 0xff) / 255
  18. let b = CGFloat((hex >> 00) & 0xff) / 255
  19.  
  20. self.init(red: r, green: g, blue: b, alpha: 1)
  21. }
  22. }
Add Comment
Please, Sign In to add comment