gpt4 book ai didi

swift - 带有 CGGradient 的 PaintCode StyleKit Swift 3.0 错误

转载 作者:搜寻专家 更新时间:2023-10-31 22:05:52 25 4
gpt4 key购买 nike

样式包代码:

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])!

也有错误

最佳答案

您还需要更改一些内容:

  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])!

关于swift - 带有 CGGradient 的 PaintCode StyleKit Swift 3.0 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39553958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com