title: iOS Autoresizing Cell Labels Sometimes Clipped
body: <p>I am writing an app (targeting iOS 10+, building with the iOS 10.3 SDK in Xcode 8.3.3) which displays a simple table view to the user. This table view is composed of a bunch of cells representing user-defined objects which have an optional title and mandatory (short) content. To display these, I am using <code>UILabel</code>, naturally.</p>
  
  <p>I am also trying to use autoresizing cells. The view controller in which all the magic occurs is a subclass of <code>UITableViewController</code> (with a grouped table view), and in its <code>loadView</code> method, I configure it to use automatic resizing with</p>
  
  <pre><code>tableView.rowHeight = UITableViewAutomaticDimension
  tableView.estimatedRowHeight = 21
  </code></pre>
  
  <p>I then configure the cells with the following constraints (using symbolic shorthand):</p>
  
  <ul>
  <li><code>nameLabel.topMargin = contentView.topMargin</code></li>
  <li><code>nameLabel.leftMargin = contentView.leftMargin</code></li>
  <li><code>nameLabel.rightMargin = contentView.rightMargin</code></li>
  <li><code>contentLabel.leftMargin = contentView.leftMargin</code></li>
  <li><code>contentLabel.rightMargin = contentView.rightMargin</code></li>
  <li><code>contentLabel.topMargin = nameLabel.bottomMargin</code></li>
  <li><code>contentView.bottomMargin = contentLabel.bottomMargin</code></li>
  </ul>
  
  <p>The labels are given <code>lineBreakMode</code>s of <code>.byWordWrapping</code> and <code>numberOfLines</code> is set to <code>0</code>. <code>translatesAutoresizingMaskIntoConstraints</code> is, of course, set to <code>false</code>. They are assigned fonts using <code>UIFont.preferredFont(forTextStyle:)</code>.</p>
  
  <p>This all works well — until the content label's exceeds the width of the cell by just a little bit. The cells resize properly if it wraps a little bit past the end of the cell, and then this content is hidden. It displays correctly, regardless of number of lines, once a certain wraparound length is reached, however. Here's a screenshot. Here, the content for the "Length" item is "This is a super duper long snippet, because we need to see how labels behave when they (more than barely) extend onto multiple lines." The content for the "Power Cycle" item is "Have you tried turning it off and back on again?" Strange, right? <a href="https://i.stack.imgur.com/znJui.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/znJui.png" alt="Screenshot"></a>
  Adding a mere "Please advise." to the end of the "Length" item results in it rendering as expected, as shown below (and it's even a nice animated change).<a href="https://i.stack.imgur.com/NmztV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NmztV.png" alt="Longer Screenshot"></a></p>
  
  <p>The content label has a low content hugging priority and the name label has a high one. The content label has a high content compression resistance priority and the name label has a low one.</p>
  
  <p>It may also be worth noting (more explicitly) that <em>this issue persists when I manually calculate cell heights using relevant APIs for sizes of strings and assign these heights explicitly in <code>tableView(_:heightForRowAt:)</code></em>.</p>
  
  <p>I've been tearing my hair out over this issue for days now. I've written many, many fixes, including some strange ones and even some that use CoreText and friends. Nothing's worked properly. The old fixes for iOS 6 and company don't work. Something's up here, and I can't find it.</p>
  
  <p>Thanks in advance for the help!</p>
  
  <hr>
  
  <p>Before you refer me to other questions, please know that I have spent hours and hours scouring the Internet (Stack Overflow and elsewhere) for solutions to this problem, and all the solutions available do not work for my situation. Posting a smug, snarky response with a link to another question or blog post probably isn't going to help, and is just annoying. Relatedly, please don't tell me to just use a default cell style.</p>