title: UIStackView and multi-line labels in a UITableViewCell
body: <p>I want to have a custom <code>UITableViewCell</code> with a number of vertically stacked <code>UILabel</code>s all of which can contain text that wraps multiple lines. With the new <code>UIStackView</code> in iOS9 and the cell self-sizing mechanism I thought this would be straightforward, but I can't get it to work. I am using Xcode 7beta3.</p>
  
  <p><img src="https://i.stack.imgur.com/JfJcK.png" alt="Table view with labels not wrapping"></p>
  
  <p>I created a simple test app. This is the setup in IB:</p>
  
  <p><img src="https://i.stack.imgur.com/odAKP.png" alt="IB setup with prototype cell"></p>
  
  <p>The <code>UIStackView</code> is vertical with <code>UIStackViewDistribution.Fill</code> and <code>UIStackViewAlignment.Fill</code> but I have basically tried all the combinations without success.</p>
  
  <p>The <code>UILabel</code>s have <code>numberOfLines = 0</code> and <code>lineBreakMode = .ByWordWrapping</code>.</p>
  
  <p>The code:</p>
  
  <pre><code>class Cell: UITableViewCell {
  
      @IBOutlet var label1: UILabel!
      @IBOutlet var label2: UILabel!
  }
  
  class MasterViewController: UITableViewController {
  
      struct Data {
          let label1: String
          let label2: String
      }
  
      var objects = [Data]()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          tableView.rowHeight = UITableViewAutomaticDimension
          tableView.estimatedRowHeight = 60
  
          createData()
      }
  
      private func createData() {
  
          for ii in 0 ..&lt; 20 {
  
              let data = Data(label1: "\(ii): hello world this is a longer string that should wrap without going weird", label2: "label2 has lots of writing as well and so should wrap onto multiple lines")
              objects.append(data)
          }
      }
  
      // MARK: - Table View
  
      override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
          return 1
      }
  
      override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return objects.count
      }
  
      override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
          let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! Cell
          let data = objects[indexPath.row]
  
          cell.label1?.text = data.label1
          cell.label2?.text = data.label2
  
          return cell
      }
  }
  </code></pre>
  
  <p>I wonder if there is a bug in the beta, because sometimes one of the labels wraps while the other doesn't.</p>
  
  <p>For example I tried nesting the <code>UIStackView</code> in another <code>UIStackView</code> as follows:</p>
  
  <p><img src="https://i.stack.imgur.com/oxcqd.png" alt="Nested UIStackView in IB"></p>
  
  <p>I made no code changes at all. Now one label wraps while the other does not:</p>
  
  <p><img src="https://i.stack.imgur.com/sbEAz.png" alt="One label wrapping only"></p>
  
  <p>Any help would be greatly appreciated!</p>