Swift 3- PaintCode StyleKit颜色错误

时间:2016-09-27 20:33:40

标签: swift3 xcode8 paint-code

在升级到Swift 3和Xcode 8之前,我的StyleKit项目运行得非常好。这是我的一些颜色代码:

   //// Color Declarations
    let purplebliss1 = UIColor(red: 0.212, green: 0.000, blue: 0.200, alpha: 1.000)
    let purplebliss2 = UIColor(red: 0.043, green: 0.529, blue: 0.576, alpha: 1.000)

//// Color Declarations
    let venice1 = UIColor(red: 0.522, green: 0.847, blue: 0.808, alpha: 1.000)
    let venice2 = UIColor(red: 0.031, green: 0.314, blue: 0.471, alpha: 1.000)
    let aqua1 = UIColor(red: 0.149, green: 0.816, blue: 0.808, alpha: 1.000)
    let aqua2 = UIColor(red: 0.102, green: 0.161, blue: 0.502, alpha: 1.000)


    //// Color Declarations
    let mantle1 = UIColor(red: 0.141, green: 0.776, blue: 0.863, alpha: 1.000)
    let mantle2 = UIColor(red: 0.318, green: 0.290, blue: 0.616, alpha: 1.000)

但是,现在说这些代码行包​​含错误:

//// Gradient Declarations
let purpleBliss = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [purplebliss2.CGColor, purplebliss2.blendedColorWithFraction(0.5, ofColor: purplebliss1).CGColor, purplebliss1.CGColor], [0, 0.27, 1])!

//// Gradient Declarations
    let mantle = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [mantle1.CGColor, mantle2.CGColor], [0, 1])!

 //// Gradient Declarations
    let veniceBeach = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [venice2.CGColor, venice1.CGColor], [0, 1])!
    let aqua = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [aqua1.CGColor, aqua2.CGColor], [0, 1])!

其一贯说的错误是:

contexttual type 'CFArray' cannot be used with array literal

我不知道如何解决这个问题。有什么建议吗?

谢谢大家:)

2 个答案:

答案 0 :(得分:1)

(更新)尝试创建这样的CFArray:

let purpleBliss = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(),
                                  colors: [purplebliss2.cgColor, purplebliss2.blendedColorWithFraction(0.5, ofColor: purplebliss1).cgColor, purplebliss1.cgColor] as CFArray,
                                 locations: [0, 0.27, 1])!

其他渐变会是这样的:

let mantle = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(),
                         colors: [mantle1.cgColor, mantle2.cgColor] as CFArray,
                         locations: [0, 1])!

let veniceBeach = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), 
                             colors: [venice2.cgColor, venice1.cgColor] as CFArray, 
                             locations: [0, 1])!

let aqua = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(),
                      colors:[aqua1.cgColor, aqua2.cgColor] as CFArray, 
                      locations: [0, 1])!

总而言之,更新到swift 3时所做的更改是:

  1. CGGradientCreateWithColors现在是CGGradient
  2. 您必须在通话中添加参数的所有标签(colorsSpacecolorslocations)。
  3. .CGColor现在是.cgColor
  4. 在Swift 3中,已删除对桥接类型的隐式转换,因此您必须自己投射CFArray

答案 1 :(得分:0)

值得一提的是,PaintCode 3完全支持导出到Swift 3。

- PaintCode支持