I am adding a CAGradientLayer to UIViewwhich is already inside UITableViewCell. This UIView has a 20 trailingand a leadingspace from UITableViewCell contentView. But this is an overflow of UIView when it starts.
var gradientLayer: CAGradientLayer!
@IBOutlet weak var view: UIView!
func createGradientLayer() {
gradientLayer = CAGradientLayer.init(layer: view.layer)
gradientLayer.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
let colory: UIColor = UIColor(red: 0, green: 189/255, blue: 237/255, alpha: 1.0)
gradientLayer.colors = [UIColor.ceruleanBlue.cgColor, colory.cgColor]
gradientLayer.startPoint = CGPoint.init(x: 0.0, y: 0.5)
gradientLayer.endPoint = CGPoint(x:1.0,y: 0.5)
self.view.layer.insertSublayer(gradientLayer, at: 0)
}
Then, in the cellForRow method, I used the following:
if indexPath.row == 0{
let cell = tableView.dequeueReusableCell(withIdentifier: "statisticsCell") as! StatisticsCommentCell
cell.view.translatesAutoresizingMaskIntoConstraints = false
return cell
}
If I changed gradientLayer.frame as below:
gradientLayer.frame.size.width = self.view.frame.width
gradientView does not overflow, but it seems to be only color ceruleanBlue.
I do not know how to solve this problem for mine UIView.
Any idea? Thanks in advance.
Screenshot from simulator with overflow problem:
Hint: usually UIViewalready completes and leads from UITableViewCell contentView.

Another problem is that when maskToBounds is added, the view looks lower

All restrictions for UIView
