title: How can I match Custom View's frame with TableViewCell frame properly?
body: <p>I have a TableView which contains image stretched into cell and I added a view for darkening the image. Since I want to draw this view only in the beginning and not every time I scroll in table I added my codes into <code>awakeFromNib</code> in TableViewCell.</p>
  
  <p><strong>TableViewCell.swift</strong></p>
  
  <pre><code>@IBOutlet weak var equipmentImageView: UIImageView!
  let darkFilter = UIView()
  
  override func awakeFromNib() {
      super.awakeFromNib()
  
      darkFilter.backgroundColor = .black
      darkFilter.layer.opacity = 0.6
      darkFilter.frame = self.equipmentImageView.frame
      equipmentImageView.addSubview(darkFilter)
  }
  </code></pre>
  
  <p>My problem is that this view will not have the same width with the ImageView, so the effect I'm trying to implement takes half of the screen.
  <a href="https://i.stack.imgur.com/TYATY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TYATY.png" alt="The dark view only applies half of the screen"></a></p>
  
  <p>I followed <a href="https://stackoverflow.com/a/39222046/6213091">this</a> solution but the problem is that this solution will only apply after the cells recreate themselves by scrolling down and up again.</p>
  
  <p><strong>TableViewCell.swift</strong></p>
  
  <pre><code>override func layoutSubviews() {
      super.layoutSubviews()
      darkFilter.backgroundColor = .black
      darkFilter.layer.opacity = 0.6
      darkFilter.frame = self.equipmentImageView.frame
      equipmentImageView.addSubview(darkFilter)
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/3AYSF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3AYSF.jpg" alt="With LayoutSubView  function"></a></p>
  
  <p>How can I apply this solution before the cells are created and will not redraw when scrolling through it?</p>