2016-08-08 23 views
0

Zurück durch ein altes Projekt wollte ich einige Funktionen hinzufügen und lief in diesen Fehler. Weiß jemand, wie man das beseitigt? Es geschah für den Code unten:Nein '|' Kandidaten produzieren den erwarteten kontextuellen Ergebnistyp 'CGGradientDrawingOptions'

UInt32(CGGradientDrawingOptions.DrawsBeforeStartLocation) | UInt32(CGGradientDrawingOptions.DrawsAfterEndLocation)) 

Unten ist die vollständige Datei:

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) 

    } 
} 

Antwort

3

CGGradientDrawingOptions seit Swift 2.0 implements OptionSetType. Das bedeutet, dass | Betreiber nicht mehr notwendig ist, und man kann es so schreiben:

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

Um weitere Informationen zu erhalten Sie können go here

+0

Großen Dank, das funktionierte. –

-1

gruppieren Versuchen Sie, sie in Array statt.