CGGradientDrawingOptions

CGGradientDrawingOptions

This question already has answers here:
No '|' candidates produce the expected contextual result type 'NSTextStorageEditActions'
(2个答案)
三年前关闭。
回到以前的一个项目中,我打算添加一些特性,但遇到了这个错误。有人知道如何消除这种情况吗?发生了以下代码:
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)

    }
}

最佳答案

CGGradientDrawingOptions自Swift 2.0implements OptionSetType起。这意味着|运算符不再是必需的,您可以这样编写它:

let options: CGGradientDrawingOptions = [.DrawsBeforeStartLocation, .DrawsAfterEndLocation]

要获取更多信息,您可以go here

关于ios - 没有'|'候选人产生预期的上下文结果类型“CGGradientDrawingOptions” ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38821227/

10-12 05:42