Add a gradient to UIView in UITableViewCell

advertisements

I have problem with add gradient layer,

This is my code:

override func awakeFromNib() {
    super.awakeFromNib()

    let colors: [AnyObject] = [
        UIColor(white: 0, alpha: 0.5).CGColor,
        UIColor(white: 0, alpha: 0.8).CGColor
    ]
    gradientLayer.colors = colors
    gradientView.layer.insertSublayer(gradientLayer, atIndex: 0)
}

override func layoutSubviews() {
    super.layoutSubviews()

    gradientLayer.frame = gradientView.frame
}

And this is result:

The gradientLayer frame is smaler than gradientView problem :(

Mabey You know how to fix it :)


Move

gradientLayer.frame = gradientView.frame

into your awakeFromNib() function.