title: How to add padding inside a UITableViewCell with self-sizing cells?
body: <p>I'm looking at the Instagram comment table view, and each cell self sizes depending on the length of the comment with some kind of padding on the top and bottom. Now I tried doing something similar, except I have a problem self-sizing the table view cell. I try to add constraints to achieve the padding effect, but the text overlaps the next cell.</p>
  
  <p>I've tried <code>tableView.contentInset</code> but it didn't change anything.</p>
  
  <p>Here's what I want:</p>
  
  <p><a href="https://i.stack.imgur.com/IqcDA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IqcDA.jpg" alt="enter image description here"></a></p>
  
  <p>Here's what ends up happening:</p>
  
  <p><a href="https://i.stack.imgur.com/pdRUR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pdRUR.png" alt="enter image description here"></a></p>
  
  <pre><code>class TableViewController: UITableViewController {
      override func viewDidLoad() {
      super.viewDidLoad()
  
      tableView.estimatedRowHeight = 130.0
      tableView.tableFooterView = UIView()
      tableView.separatorInset.left = 50
      tableView.registerClass(CommentCellView.self, forCellReuseIdentifier: cellid)
      tableView.rowHeight = UITableViewAutomaticDimension
      tableView.contentInset = UIEdgeInsetsMake(15, 15, 15, 15)
  
  
  }
  
  override func viewDidAppear(animated: Bool) {
      tableView.reloadData()
  }
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCellWithIdentifier(cellid, forIndexPath: indexPath) as! CommentCellView
      cell.layoutIfNeeded()
      return cell
  }
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return 10
  
  }
  
  override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat {
      return 60.0
  }
  
  }
  
  class CommentCellView: UITableViewCell {
      override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
      super.init(style: .Subtitle, reuseIdentifier: reuseIdentifier)
  
  
      contentView.addSubview(commentLabel)
      commentLabel.leftAnchor.constraintEqualToAnchor(contentView.leftAnchor).active = true
      commentLabel.rightAnchor.constraintEqualToAnchor(contentView.rightAnchor).active = true
      commentLabel.topAnchor.constraintEqualToAnchor(contentView.topAnchor, constant: 10).active = true
      commentLabel.bottomAnchor.constraintEqualToAnchor(contentView.bottomAnchor, constant: 10).active = true
  
      self.contentView.layoutMargins = UIEdgeInsetsMake(15, 15, 15, 15)
  }
  </code></pre>