ios - 我的代码有什么问题。我正在尝试为表格 View Controller 着色

标签 ios swift colors tableview

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/

相关文章:

iOS 删除键没有反应

ios - 如何将 CoreLocation 坐标转换为字符串?

swift 4 : Add pencil to sign PDF file

ios - 在 UITableViewCell 中调用 UIAlertController

javascript - 为字符串中的相同元素着色

python - matplotlib 颜色图

ios - 带有图像和蒙版的动画旋转加载程序

iphone - 使用 Storyboard 将 UINavigationController 插入 UIViewController

ios - 在 Swift 中使用 for 循环完成

iphone - iPhone 上导航栏按钮的默认颜色是什么?