继续自己的第一个swift项目的奋斗之路!

来源:互联网 发布:淘宝流量一下子跌下来 编辑:程序博客网 时间:2024/06/15 08:47

继续研究!继续学习!

字典还可以这样遍历
var someDict:[Int:String] = [1:”One”, 2:”Two”, 3:”Three”]
for (key, value) in someDict.enumerate() {
print(“字典 key (key) - 字典 (key, value) 对 (value)”)
}

var someDict:[Int:String] = [1:”One”, 2:”Two”, 3:”Three”]

let dictKeys =  [int](someDict.keys)let dictValues = [string](someDict.values)

用习惯了的16进制颜色码转UIColor

由于swift的新特性,对UIcolor进行拓展不需要像OC一样再建一个类,写明是拓展color,一下代码放在你认为的任何的合理地方都能使用

extension UIColor {    //可以设置透明度    class func rgbaColorFromHex(rgb:Int, alpha: CGFloat) ->UIColor {        return UIColor(red: ((CGFloat)((rgb & 0xFF0000) >> 16)) / 255.0,                       green: ((CGFloat)((rgb & 0xFF00) >> 8)) / 255.0,                       blue: ((CGFloat)(rgb & 0xFF)) / 255.0,                       alpha: alpha)    }    //    class func rgbColorFromHex(rgb:Int) -> UIColor {        return UIColor(red: ((CGFloat)((rgb & 0xFF0000) >> 16)) / 255.0,                       green: ((CGFloat)((rgb & 0xFF00) >> 8)) / 255.0,                       blue: ((CGFloat)(rgb & 0xFF)) / 255.0,                       alpha: 1.0)    }}
0 0
原创粉丝点击