swift项目常用的扩展
1.UIColor的扩展
extension UIColor {
open static func rgbColor(_ r:CGFloat, _ g:CGFloat, _ b:CGFloat, _ alpha:CGFloat = 1.0) -> UIColor{
let color:UIColor = UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: alpha)
return color
}
open static func randomColor() -> UIColor {
return UIColor(red: randomColorCount(0, 256)/255.0, green: randomColorCount(0, 256)/255.0, blue: randomColorCount(0, 256)/255.0, alpha: 1.0)
}
private static func randomColorCount(_ startIndex:Int, _ endIndex:Int) -> CGFloat{
let range = Range<Int>(startIndex...endIndex)
let count = UInt32(range.upperBound - range.lowerBound)
let v = Int(arc4random_uniform(count))+range.lowerBound
return CGFloat(v)
}
open static f