override func drawRect(rect: CGRect) {
let green: UIColor = UIColor(red: 79, green: 255, blue: 110, alpha: 1)
let lightGreen: UIColor;(red: 190, green: 225, blue: 211, alpha: 1)
let context = UIGraphicsGetCurrentContext()
let greenGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [lightGreen.CGColor, green.CGColor],[0, 1],
let backgroundPath = UIBezierPath(rect: CGRectMake(0, 0, self.frame.width, self.frame.height)),
CGContextSaveGState(context),
backgroundPath.addClip(),
CGContextDrawLinearGradient(context, greenGradient, CGPointMake(160, 0), CGPointMake(160, 568),
UInt32(kCGGradientDrawsBeforeStartLocation) | UInt32 (kCGGradientDrawsAfterEndLocation)),
CGContextRestoreGState(context)
我一直在尝试调试这个大约一个小时,并且构建每次都失败。
答案 0 :(得分:1)
假设颜色不起作用,
尝试此设置颜色
let green = UIColor(red: 79/255.0, green: 255/255.0, blue: 110/255.0, alpha: 1)
let lightGreen = UIColor(red: 190/255.0, green: 225/255.0, blue: 211/255.0, alpha: 1)
答案 1 :(得分:1)
您在第二行添加了分号:
let lightGreen: UIColor;(red: 190, green: 225, blue: 211, alpha: 1)
删除此分号。它会正常工作。