UIColor 实用 extension
2022-09-05 本文已影响0人
_浅墨_
extension UIColor {
static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 1)
}
static let twitterBlue = UIColor.rgb(red: 29, green: 161, blue: 242)
/**
十六进制方法
*/
static func hexColor(_ hexValue : Int, alphaValue: Float ) -> UIColor {
return UIColor(red: CGFloat((hexValue & 0xFF0000) >> 16) / 255,
green: CGFloat((hexValue & 0x00FF00) >> 8) / 255,
blue: CGFloat(hexValue & 0x0000FF) / 255,
alpha: CGFloat(alphaValue))
}
static func hexColor(_ hexValue : Int) -> UIColor {
return hexColor(hexValue,alphaValue: 1)
}
convenience init(_ hexValue : Int, alphaValue: Float) {
self.init(red: CGFloat((hexValue & 0xFF0000) >> 16) / 255,
green: CGFloat((hexValue & 0x00FF00) >> 8) / 255,
blue: CGFloat(hexValue & 0x0000FF) / 255,
alpha: CGFloat(alphaValue))
}
// convenience init(_ hexValue : Int) {
// self.init(hexValue,alphaValue:1)
// }
}