public extension UIColor {
convenience init(colorHex hex: UInt) {
self.init(red: CGFloat((hex & 0xFF0000) >> 16) / 255,
green: CGFloat((hex & 0x00FF00) >> 8) / 255,
blue: CGFloat(hex & 0x0000FF) / 255, alpha: 1)
}
}
使用
self.view.backgroundColor = UIColor(colorHex: 0xf2f2f2)
网友评论