import UIKit
extension UIColor{
//MARK: - RGB
classfunc RGBColor(red : CGFloat,green : CGFloat,blue :CGFloat ) -> UIColor {
return UIColor(red: red /255.0,green: green / 255.0,blue: blue / 255.0,alpha:1)
}
classfunc RGBColor(_ RGB:CGFloat) -> UIColor {
return RGBColor(red: RGB,green: RGB,blue: RGB)
}
//MARK: - 16进制字符串转UIColor
classfunc colorWithHexString(_ hex:String) ->UIColor {
return colorWithHexString(hex,11)"> classfunc colorWithHexString (_ hex:String,alpha:CGFloat) -> UIColor {
var cString:String = hex.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString = (cString asNSString).substring(from:1)
}
elseif (cString.hasPrefix("0X") || cString.hasPrefix("0x")) {
cString = (cString asNSString).substring(to: 2)
if ((cStringas NSString).length !=6) {
return gray
let rString = (cStringas NSString).substring(to:2)
let gString = ((cStringas NSString).substring(from:2) asNSString).substring(to: 2)
let bString = ((cStringas NSString).substring(from:4) asNSString).substring(to: 2)
var r:CUnsignedInt =0,g:CUnsignedInt =0,b:CUnsignedInt =0;
Scanner(string: rString).scanHexInt32(&r)
Scanner(string: gString).scanHexInt32(&g)
Scanner(string: bString).scanHexInt32(&b)
return UIColor(red: CGFloat(r) /255.0,green: CGFloat(g) /255.0,blue: CGFloat(b) /255.0,alpha: alpha)
}
//常用的颜色
//主题色
classfunc normalColor() -> UIColor {
return colorWithHexString("#8ebf30")
//浅灰色
classfunc color666() -> UIColor{
return colorWithHexString("#666666")
classfunc color333() -> UIColor{
return colorWithHexString("#333333")
//描述文字颜色
classfunc color999() -> UIColor{
return colorWithHexString("#999999")
//价格的颜色
classfunc colorff3635() -> UIColor{
return colorWithHexString("#ff3635")
//tableView背景颜色
classfunc colorf6f6f6() -> UIColor{
return colorWithHexString("#f6f6f6")
//分割线颜色
classfunc coloreee() -> UIColor{
return colorWithHexString("#eeeeee")
//分割线颜色2
classfunc colore9e9e9() -> UIColor{
return colorWithHexString("#e9e9e9")
}