本文介绍了PaintCode StyleKit Swift 3.0 错误与 CGGradient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

StyleKit 代码:

StyleKit Code:

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

也是错误

推荐答案

您还需要更改一些内容:

There are a few more things you need to change:

  1. UIColor.whiteColor() 现在是 UIColor.white.
  2. .CGColor 现在是 .cgColor
  3. 您需要将颜色数组转换为 CFArray.Swift 3 中不再进行对桥接类型的隐式转换.
  4. Swift 可以推断 redGradient 的类型,因此您可以删除 : CGGradient.
  1. UIColor.whiteColor() is now UIColor.white.
  2. .CGColor is now .cgColor
  3. You need to cast your colors array to CFArray. Implicit casts to bridged types are no longer done in Swift 3.
  4. Swift can infer the type of redGradient so you can drop the : CGGradient.

通过这些更改,代码变为:

With these changes, the code becomes:

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

这篇关于PaintCode StyleKit Swift 3.0 错误与 CGGradient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:27