没有'|'候选人产生预期的上下文结果类型 'CGGradientDrawingOptions'
No '|' candidates produce the expected contextual result type 'CGGradientDrawingOptions'
回顾一个旧项目,我打算添加一些功能,运行 到这个错误中。有谁知道如何消除这个?它发生在以下代码中:
UInt32(CGGradientDrawingOptions.DrawsBeforeStartLocation) | UInt32(CGGradientDrawingOptions.DrawsAfterEndLocation))
完整文件如下:
import UIKit
class BackgroundView: UIView {
override func drawRect(rect: CGRect) {
// Background View
//// Color Declarations
var lightPurple: UIColor = UIColor(red: 0.377, green: 0.075, blue: 0.778, alpha: 1.000)
var darkPurple: UIColor = UIColor(red: 0.060, green: 0.036, blue: 0.202, alpha: 1.000)
let context = UIGraphicsGetCurrentContext()
//// Gradient Declarations
let purpleGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [lightPurple.CGColor, darkPurple.CGColor], [0, 1])
//// Background Drawing
let backgroundPath = UIBezierPath(rect: CGRectMake(0, 0, self.frame.width, self.frame.height))
CGContextSaveGState(context)
backgroundPath.addClip()
CGContextDrawLinearGradient(context, purpleGradient,
CGPointMake(160, 0),
CGPointMake(160, 568),
UInt32(CGGradientDrawingOptions.DrawsBeforeStartLocation) | UInt32(CGGradientDrawingOptions.DrawsAfterEndLocation))
CGContextRestoreGState(context)
}
}
尝试将它们分组到 Array
中。
CGGradientDrawingOptions
自 Swift 2.0 implements OptionSetType。这意味着不再需要 |
运算符,您可以这样写:
let options: CGGradientDrawingOptions = [.DrawsBeforeStartLocation, .DrawsAfterEndLocation]
要获取更多信息,您可以go here
回顾一个旧项目,我打算添加一些功能,运行 到这个错误中。有谁知道如何消除这个?它发生在以下代码中:
UInt32(CGGradientDrawingOptions.DrawsBeforeStartLocation) | UInt32(CGGradientDrawingOptions.DrawsAfterEndLocation))
完整文件如下:
import UIKit
class BackgroundView: UIView {
override func drawRect(rect: CGRect) {
// Background View
//// Color Declarations
var lightPurple: UIColor = UIColor(red: 0.377, green: 0.075, blue: 0.778, alpha: 1.000)
var darkPurple: UIColor = UIColor(red: 0.060, green: 0.036, blue: 0.202, alpha: 1.000)
let context = UIGraphicsGetCurrentContext()
//// Gradient Declarations
let purpleGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [lightPurple.CGColor, darkPurple.CGColor], [0, 1])
//// Background Drawing
let backgroundPath = UIBezierPath(rect: CGRectMake(0, 0, self.frame.width, self.frame.height))
CGContextSaveGState(context)
backgroundPath.addClip()
CGContextDrawLinearGradient(context, purpleGradient,
CGPointMake(160, 0),
CGPointMake(160, 568),
UInt32(CGGradientDrawingOptions.DrawsBeforeStartLocation) | UInt32(CGGradientDrawingOptions.DrawsAfterEndLocation))
CGContextRestoreGState(context)
}
}
尝试将它们分组到 Array
中。
CGGradientDrawingOptions
自 Swift 2.0 implements OptionSetType。这意味着不再需要 |
运算符,您可以这样写:
let options: CGGradientDrawingOptions = [.DrawsBeforeStartLocation, .DrawsAfterEndLocation]
要获取更多信息,您可以go here