I have a problem with a view inside a tableViewCell. So I have a tableViewCell, inside of that I have a UIView I called "containerView". Now I want the background of the containerView to be a gradient from light gray to dark gray. In the following code you can see how I set the layer and everything, but for some reason the "backgroundColor" with the gradient is a little off to the right and downwards. Hope you can help me fix this problem, it's the first time I am working with gradient so please be patient :D
import UIKit
class customCell: UITableViewCell {
@IBOutlet var containerView: UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let layerView = UIView()
layerView.layer.frame = containerView.layer.frame
let layer = CAGradientLayer()
layer.frame = containerView.layer.frame
layer.colors = [UIColor.lightGrayColor().CGColor, UIColor.darkGrayColor().CGColor]
layerView.layer.addSublayer(layer)
containerView.addSubview(layerView)
containerView.sendSubviewToBack(layerView)
}
}