func colorWithHexString (hex:String) -> UIcolor { | |
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString | |
if (cString.hasPrefix("#")) { | |
cString = cString.substringFromIndex(1) | |
} | |
if (countElements(cString) != 6) { | |
return UIcolor.graycolor() | |
} | |
var rString = cString.substringToIndex(2) | |
var gString 2)2) | |
var bString 4)2) | |
var r:CUnsignedInt = 0,g:CUnsignedInt = 0,b:CUnsignedInt 0; | |
NSScanner.scannerWithString(rString).scanHexInt(&r) | |
.scannerWithString(gString)&g) | |
.scannerWithString(bString)&b) | |
return UIcolor(red: float(r) / 255.float(g) / 255float(b) float(1)) | |
@H_301_235@ } |
以上是内存溢出为你收集整理的Swift String to UIColor(16进制字符串转颜色值)全部内容,希望文章能够帮你解决Swift String to UIColor(16进制字符串转颜色值)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)