颜色工具类UIColorExtension-swift
2017-03-01 本文已影响96人
HAKA
import UIKit
extension UIColor {
static func rgb(_ red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
return UIColor.init(red: red/255, green: green/255, blue: blue/255, alpha: 1)
}
static func colorWithHex(_ hex: UInt) -> UIColor {
let r: CGFloat = CGFloat((hex & 0xff0000) >> 16)
let g: CGFloat = CGFloat((hex & 0x00ff00) >> 8)
let b: CGFloat = CGFloat(hex & 0x0000ff)
return rgb(r, green: g, blue: b)
}
}