由于设计图多数使用十六进制颜色,为UIColor写一个类目,便于设置颜色
import UIKit
extension UIColor{
class func colorWithHex(hexColor:u_long) -> UIColor{
return UIColor.colorWithHex(hexColor: hexColor, alpha: 1.0)
}
class func colorWithHex(hexColor:u_long,alpha:CGFloat) -> UIColor {
let red : CGFloat = CGFloat((hexColor & 0xFF0000) >> 16) / 255.0
let green : CGFloat = CGFloat((hexColor & 0xFF00) >> 8) / 255.0
let blue : CGFloat = CGFloat(hexColor & 0xFF) / 255.0
return UIColor.init(red: red, green: green, blue: blue, alpha: alpha)
}
}
//调用
UIColor.colorWithHex(hexColor: 0xd3d3d3) //一定不要忘记了前面的0X,这个表示十六进制数