Swift 3 unresolved identifier CGColorGetComponents

2019-07-30 11:47发布

问题:

This question already has an answer here:

  • Xcode 8 Beta 4 CGColor.components unavailable 5 answers

How can I refactor this code in Swift 3?:

    extension UIColor {
        var hexString: String {
            // Produces "Use of unresolved identifier 'CGColorGetComponents'"
            let components = CGColorGetComponents(self.cgColor)
            ....
        }
    }

回答1:

var r:CGFloat = 0, g:CGFloat = 0, b:CGFloat = 0, a:CGFloat = 0
self.getRed(&r, green: &g, blue: &b:, alpha: &a)
...