Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 替换随机颜色数组中的属性CGColorGetComponents(在swift 4中不可用)_Ios_Swift - Fatal编程技术网

Ios 替换随机颜色数组中的属性CGColorGetComponents(在swift 4中不可用)

Ios 替换随机颜色数组中的属性CGColorGetComponents(在swift 4中不可用),ios,swift,Ios,Swift,如何替换此随机颜色数组中的CGColorGetComponents属性(在swift 4中不可用) fileprivate func hexyColor(color: UIColor) -> String { let components = CGColorGetComponents(color.cgColor) var hex = "" for i in 0...2 { let int = Int(components[i] * 255)

如何替换此随机颜色数组中的CGColorGetComponents属性(在swift 4中不可用)

fileprivate func hexyColor(color: UIColor) -> String {

    let components = CGColorGetComponents(color.cgColor)
    var hex = ""

    for i in 0...2 {
        let int = Int(components[i] * 255)
        let hexCode = String(int, radix: 16)

        if hexCode.count < 2 {
            hex = hex + "0\(hexCode)"
        } else {
            hex = hex + hexCode
        }
    }

    return "#\(hex)"
}
fileprivate func hexyColor(颜色:UIColor)->字符串{
let components=CGColorGetComponents(color.cgColor)
var hex=“”
因为我在0…2{
设int=int(分量[i]*255)
让hexCode=字符串(整数,基数:16)
如果hexCode.count小于2{
十六进制=十六进制+0\(十六进制代码)
}否则{
十六进制=十六进制+十六进制代码
}
}
返回“#\(十六进制)”
}

thx提前回复:)

它已被重命名,所以只需使用

let components = color.cgColor.components

我认为这是一个重复的问题,看到了吗