StyleKit代码:
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])!
也是错误
答案 0 :(得分:6)
还有一些事情需要改变:
UIColor.whiteColor()
现在是UIColor.white
。.CGColor
现在是.cgColor
CFArray
。 Swift 3中不再对桥接类型进行隐式转换。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])!