title: UIView in custom UITableViewCell redraws when scrolling
body: <p>I am adding an <code>UIView</code> inside my custom <code>UITableView</code> to draw more or less like an availability bar. I have two problems with it:</p>
  
  <p>1.- The view only gets drawn when the new cells appear on screen not at launch time as you can see in the GIF below.</p>
  
  <p>2.- When scrolling <code>tableView</code> several times the <code>UIView</code> on each cell is redrawn so they overlap with each other</p>
  
  <p><a href="http://imgur.com/a/OCJiw" rel="nofollow">GIF</a></p>
  
  <p><strong>Code of UITableViewCell :</strong></p>
  
  <pre><code>import UIKit
  
  class CustomTableViewcell: UITableViewCell {
  
      @IBOutlet weak var bikeStationLabel: UILabel!
      @IBOutlet weak var progressView: UIView!
      @IBOutlet weak var distanceLabel: UILabel!
  
  
      override internal func awakeFromNib() {
  
      }
  }
  </code></pre>
  
  <p>I think nothing is wrong there, it's simple. My problem I think comes with the <code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell</code> method. What I have so far is:</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let cell: CustomTableViewcell! = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomTableViewcell
      cell.backgroundColor = UIColor(red: 120/255, green: 120/255, blue: 120/255, alpha: 0.5)
  
      // Dump the data into a single variable to shorten the code
      let stations = parsedData[indexPath.row]
  
  
      // Draw a rectangle on each progress bar depending on the availability of the bikes
      let availabilityGraph = UIBezierPath(roundedRect: CGRect(x: cell.progressView.frame.minX, y: cell.progressView.frame.minY, width: CGFloat(Float(stations.freeBikes!) / (Float(stations.freeBikes!) + Float(stations.freeDocks!))) * cell.progressView.frame.width, height: cell.progressView.frame.height), cornerRadius: 0)
      let shapeLayer = CAShapeLayer()
      shapeLayer.path = availabilityGraph.cgPath
  
      //change the fill color
      shapeLayer.fillColor = UIColor.clear().cgColor
      //you can change the line width
      shapeLayer.lineWidth = cell.frame.height
  
      shapeLayer.strokeColor = UIColor(red: 96/255, green: 96/255, blue: 96/255, alpha: 0.8).cgColor
      cell.progressView.layer.addSublayer(shapeLayer)
  
      cell.bikeStationLabel.textColor = UIColor.white()
      cell.bikeStationLabel.text = stations.stationName!
  
      cell.distanceLabel.text = "100 m"
  
      return cell
  }
  </code></pre>