Initialize UIColor from RGB hex in Swift

Want to initialize a UIColor object from a hex code? Create a new Swift class named “UIColor+FromRGB.swift” with the following content: import UIKit extension UIColor { static func fromRGB(colorCode: String, alpha: Float = 1.0) -> UIColor { let scanner = NSScanner(string:colorCode) var color:UInt32 = 0; scanner.scanHexInt(&color) let mask = 0x000000FF let r = CGFloat(Float(Int(color >>… Continue reading Initialize UIColor from RGB hex in Swift