title: Whole UITableviewcell is highlighted instead of rounded view inside the cell
body: <p>I was trying to achieve the rounded tableview cell effect, so I tried to mess with layoutSubviews in my custom cell class:</p>
  
  <pre><code>override func layoutSubviews() {        
      // Set the width of the cell
      self.bounds = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width - 40, self.bounds.size.height)
      super.layoutSubviews()
  }
  </code></pre>
  
  <p>I heard that it is not recommended to change the width of the cell itself, and that adding a UIView (called mainView in the code) to the cell and adding constraints + corner radius would do the job.</p>
  
  <p>My custom cell class is now:</p>
  
  <pre><code>class customTableViewCell: UITableViewCell {
  
      @IBOutlet weak var mainView: UIView!
  
      override func awakeFromNib() {
          super.awakeFromNib()
  
          mainView.layer.borderWidth = 2
          mainView.layer.cornerRadius = 20
          mainView.layer.borderColor = UIColor.black.cgColor
          mainView.layer.masksToBounds = true
          // Initialization code
      }
  
      override func setSelected(_ selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
          // Configure the view for the selected state
      }
  }
  </code></pre>
  
  <p>and here are the relevant components to my ViewController that holds the mainTableView:</p>
  
  <pre><code>    override func viewDidLoad() {
              super.viewDidLoad()
  
              mainTableView.rowHeight = 100
              mainTableView.backgroundColor = UIColor.clear
  
              mainTableView.delegate = self
              mainTableView.dataSource = self
              // Do any additional setup after loading the view, typically from a nib.
          }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
              let cell = self.mainTableView.dequeueReusableCell(withIdentifier: "customCell") as! customTableViewCell
  
              // note that indexPath.section is used rather than indexPath.row
              cell.textLabel?.text = self.animals[indexPath.row]
              cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 16)
              cell.textLabel?.textAlignment = .center
  
              // add border and color
  
              cell.backgroundColor = UIColor.clear
              cell.layer.borderColor = UIColor.clear.cgColor
              cell.layer.borderWidth = 1
              //cell.layer.cornerRadius = 8
              cell.clipsToBounds = true
  
              return cell
          }
  </code></pre>
  
  <p><strong>My result is this:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/5XBxw.png" rel="nofollow noreferrer">screenshot of simulator</a></p>
  
  <p>As you can tell, the whole cell is highlighted and not just what is inside.</p>
  
  <p>My remaining question is - Is there a way to make only the UIView inside the contentView of the cell to be highlighted instead of the whole cell? Or should I just not enable selection and highlighting.</p>
  
  <p>Please let me know. Thanks.</p>