ios - 没有 '|' 候选产生预期的上下文结果类型 'CGGradientDrawingOptions'

标签 ios swift xcode swift2

<分区>

回顾一个旧项目,我打算添加一些功能,但遇到了这个错误。有谁知道如何消除这个?它发生在下面的代码中:

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.0 implements OptionSetType .这意味着不再需要 | 运算符,您可以这样写:

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

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

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

相关文章:

ios - 使用调度组时如何使公共(public)资源线程安全?

iphone - 跟踪 Xcode 中的变量或内存变化?

ios - 无法将对象保存到 CoreData

ios - 在 iOS 和 macOS 之间编码和解码 Int 值

ios - 将完成处理程序中的值/对象获取到其外部的数组中

swift - 如何快速添加到 UILabel 的链接?

swift - UNNotificationServiceExtension 退出调用 CNContactStore enumerateContacts

ios - 从设备重新打开应用程序后不显示 NSLog

ios - 在 iOS 中滚动时保留 TableView 单元格中的按钮状态

ios - 自定义后退按钮在 iOS 中抛出异常