title: CAGradientLayer overflows on UIView when using in UITableViewCell
body: <p>I've add CAGradientLayer to a <code>UIView</code> that've already inside in <code>UITableViewCell</code>. This UIView has 20 <code>trailing</code> and <code>leading</code> space from the <code>UITableViewCell</code> <code>contentView</code>. But that UIView's overflow when it running.</p>
  
  <pre><code>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)
          //        gradientLayer.frame = CGRect(x: 0, y: 0, width: self.contentView.frame.size.width, 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.mask = gradientLayer
          self.view.layer.insertSublayer(gradientLayer, at: 0)
      }
  </code></pre>
  
  <p>Then in the cellForRow method, I used like this:</p>
  
  <pre><code>if indexPath.row == 0{
              let cell = tableView.dequeueReusableCell(withIdentifier: "statisticsCell") as! StatisticsCommentCell
  
  //            cell.frame.size.width = UIScreen.main.bounds.size.width
              cell.view.translatesAutoresizingMaskIntoConstraints = false
              return cell
          }
  </code></pre>
  
  <p>If I changed gradientLayer.frame like below:</p>
  
  <pre><code>gradientLayer.frame.size.width = self.view.frame.width
  </code></pre>
  
  <p>the gradientView is not overflow but there seems just <code>ceruleanBlue</code> color. </p>
  
  <p>I do not any idea how can I solve this problem for my <code>UIView</code>.</p>
  
  <p>Any idea? Thanks in advance. </p>
  
  <p>Its a screenshot from the simulator that have overflow problem:</p>
  
  <p>Hint: Normally the <code>UIView</code> has already trailing and leading from the <code>UITableViewCell</code>'s <code>contentView</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/QxQj0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QxQj0.png" alt="enter image description here"></a></p>
  
  <p>Another problem is when I add maskToBounds the view seems like below</p>
  
  <p><a href="https://i.stack.imgur.com/vjdvA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vjdvA.png" alt="enter image description here"></a></p>
  
  <p>All constraints for <code>UIView</code></p>
  
  <p><a href="https://i.stack.imgur.com/rmIhW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rmIhW.png" alt="enter image description here"></a></p>