Xcode 8 Beta 4 CGColor.components unavailable

前端 未结 5 1672
醉梦人生
醉梦人生 2021-01-21 07:43

Whilst the code below worked previously, it has stopped working in Xcode 8 Beta 4, presumably because the components return was a very un-Swift-y C-array of floats,

5条回答
  •  执笔经年
    2021-01-21 08:23

    extension UIColor {
        var all4Components:(red:CGFloat, green:CGFloat, blue: CGFloat, alpha:CGFloat) {
        let components = self.cgColor.components!
        let red = components[0]
        let green = components[1]
        let blue = components[2]
        let alpha = components[3]
        return (red:red, green:green, blue: blue, alpha:alpha)
    
        }
    }
    

提交回复
热议问题