Crash for white color
farabi opened this issue · comments
Saad El Oulladi commented
Hello,
Thank you for this nice lib.
I'm getting a crash when selecting white color.
open var blueValue: CGFloat{ return cgColor.components! [2] }
Fatal error: Index out of range ;)
KentaIwami commented
I avoided a same problem as follows.
MKColorPicker.allColors.append(UIColor.hex("#FFFFFF", alpha: 1.0))
UIColor extension is here.
extension UIColor {
class func hex ( _ hexStr : String, alpha : CGFloat) -> UIColor {
var hexString = hexStr as NSString
hexString = hexString.replacingOccurrences(of: "#", with: "") as NSString
let scanner = Scanner(string: hexString as String)
var color: UInt32 = 0
if scanner.scanHexInt32(&color) {
let r = CGFloat((color & 0xFF0000) >> 16) / 255.0
let g = CGFloat((color & 0x00FF00) >> 8) / 255.0
let b = CGFloat(color & 0x0000FF) / 255.0
return UIColor(red:r,green:g,blue:b,alpha:alpha)
} else {
print("invalid hex string")
return UIColor.clear;
}
}
}