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)
我已经尝试调试了大约一个小时,但每次构建都失败。
最佳答案
假设颜色没有得到处理,
试试这个来设置颜色
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)
关于ios - 我的代码有什么问题。我正在尝试为表格 View Controller 着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31445333/