2016-08-11 33 views
1

我怎樣才能在斯威夫特重構這個代碼3?:斯威夫特3個懸而未決的標識符CGColorGetComponents

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

這應該是'cgColor.components',雖然這不會因爲Xcode中8的測試版4款工作,[見本問答](http://stackoverflow.com/questions/38769322/xcode-8-beta-4-cgcolor-components-unavailable)瞭解更多信息。 – Hamish

+0

你可以使用getRed方法apple-reference-documentation:// hsPr9ZXOsl –

回答

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