十六進(jìn)制轉(zhuǎn)化顏色
UI妹子通常都是給一個(gè)顏色的十六進(jìn)制標(biāo)示,在開發(fā)中通過擴(kuò)展UIColor實(shí)現(xiàn)一個(gè)十六進(jìn)制轉(zhuǎn)化RGB Color
// MARK: UIColor 擴(kuò)展
public extension UIColor {
/// 根據(jù)16進(jìn)制返回UIColor
///
/// - Parameter rgbValue: ex:0xff9933
/// - Returns: alpha:1.0
class func kRGBColorWithHex(_ rgbValue:Int) -> UIColor {
return kRGBColorWithHex(rgbValue, alpha: 1.0)
}
/// 根據(jù)16進(jìn)制和alpha返回UIColor
///
/// - Parameters:
/// - rgbValue: ex:0xffffff(1111 1111 1111 1111 1111 1111) & 0xff0000(1111 1111 0000 0000 0000 0000) -> value:1111 1111 0000 0000 0000 0000
/// r:value >> 16 得到:1111 1111 ->轉(zhuǎn)換為10進(jìn)制數(shù):255
/// - alpha: 透明度
/// - Returns: UIColor
class func kRGBColorWithHex(_ rgbValue:Int, alpha:CGFloat) -> UIColor {
let r : CGFloat = (CGFloat)((rgbValue & 0xFF0000) >> 16) / 255.0
let g : CGFloat = (CGFloat)((rgbValue & 0xFF00) >> 8) / 255.0
let b : CGFloat = (CGFloat)((rgbValue & 0xFF) ) / 255.0
return UIColor.init(red: r, green: g, blue: b, alpha: alpha)
}
}