2016-09-18 48 views
3

StyleKit代码:PaintCode StyleKit夫特3.0错误与CGGradient

static let red: UIColor = UIColor(red: 0.800, green: 0.000, blue: 0.000, alpha: 1.000) 
static let blue: UIColor = UIColor(red: 0.200, green: 0.600, blue: 1.000, alpha: 1.000) 
static let green: UIColor = UIColor(red: 0.000, green: 0.600, blue: 0.200, alpha: 1.000) 
static let yinying: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 0.200) static let redGradient: CGGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [UIColor.whiteColor().CGColor, UIColor.whiteColor().blendedColorWithFraction(0.5, ofColor: StyleKitMarkSix.red).CGColor, StyleKitMarkSix.red.CGColor], [0, 0, 1])! 
static let blueGradient: CGGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [UIColor.whiteColor().CGColor, UIColor.whiteColor().blendedColorWithFraction(0.5, ofColor: StyleKitMarkSix.blue).CGColor, StyleKitMarkSix.blue.CGColor], [0, 0, 1])! 
static let greenGradient: CGGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [UIColor.whiteColor().CGColor, UIColor.whiteColor().blendedColorWithFraction(0.5, ofColor: StyleKitMarkSix.green).CGColor, StyleKitMarkSix.green.CGColor], [0, 0, 1])! 
static let blackGradient: CGGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [UIColor.whiteColor().CGColor, UIColor.whiteColor().blendedColorWithFraction(0.5, ofColor: UIColor.blackColor()).CGColor, UIColor.blackColor().CGColor], [0, 0, 1])! 

错误消息:

Contextual type 'CFArray' cannot be used with array literal 

我已经改变:

static let redGradient: CGGradient = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: [UIColor.whiteColor().CGColor, UIColor.whiteColor().blendedColorWithFraction(0.5, ofColor: StyleKitMarkSix.red).CGColor, StyleKitMarkSix.red.CGColor] , locations:[0, 0, 1])! 

也错误

回答

6

有一个还有几件事需要改变:

  1. UIColor.whiteColor()现在是UIColor.white
  2. .CGColor现在是.cgColor
  3. 您需要将您的颜色数组转换为CFArray。隐式强制转换为桥接类型不再在Swift 3中完成。
  4. Swift可以推断出redGradient的类型,因此您可以删除: CGGradient

有了这些变化,代码变为:

static let redGradient = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), 
    colors: [UIColor.white.cgColor, UIColor.white.blendedColorWithFraction(0.5, ofColor: StyleKitMarkSix.red).cgColor, StyleKitMarkSix.red.cgColor] as CFArray, 
    locations: [0, 0, 1])! 
+0

感谢申请职位〜 –