extension UIcolor { convenIEnce init (hex:String) { var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercased() // error appears on this line if (cString.hasPrefix("#")) { cString = (cString as Nsstring).substring(from: 1) } let rString = (cString as Nsstring).substring(to: 2) let gString = ((cString as Nsstring).substring(from: 2) as Nsstring).substring(to: 2) let bString = ((cString as Nsstring).substring(from: 4) as Nsstring).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) self.init(red: CGfloat(r) / 255.0,green: CGfloat(g) / 255.0,blue: CGfloat(b) / 255.0,Alpha: CGfloat(1)) }}
我猜这个错误是由于’stringByTrimmingCharactersInSet’的语法变化而导致的.这个更正是什么?
解决方法 新的语法是这样的:var cString = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased()
作为一个建议,您不需要指定cString是一个字符串,因为这是假定与您分配给它的值.
总结以上是内存溢出为你收集整理的ios – 类型’String’的值没有成员’stringByTrimmingCharactersInSet’全部内容,希望文章能够帮你解决ios – 类型’String’的值没有成员’stringByTrimmingCharactersInSet’所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)