UIColor之十六进制转换

来源:互联网 发布:滇虹药业淘宝旗舰店 编辑:程序博客网 时间:2024/04/20 04:14
    class func colorWithHex(hex: String, alpha: CGFloat = 1.0) -> UIColor {        var rgb: CUnsignedInt = 0;        let scanner = NSScanner(string: hex)                if hex.hasPrefix("#") {            // skip '#' character            scanner.scanLocation = 1        }        scanner.scanHexInt(&rgb)                let r = CGFloat((rgb & 0xFF0000) >> 16) / 255.0        let g = CGFloat((rgb & 0xFF00) >> 8) / 255.0        let b = CGFloat(rgb & 0xFF) / 255.0                return UIColor(red: r, green: g, blue: b, alpha: alpha)    }

0 0
原创粉丝点击