title: How to create a multi-line UILabel, with a maximum width?
body: <p>I'm writing a simple IRC client that I'm modeling after Twitter's iOS app appearance. I've taken a screenshot of the Twitter app, for reference:</p>
  
  <p><a href="https://i.imgur.com/ftww8.png" rel="nofollow noreferrer">
     <img src="https://i.imgur.com/ftww8.png" height="300" />
  </a></p>
  
  <p>It looks like a simple table view with a few labels inside of each cell. So, in my app, I am programmatically creating a table and the cell formatting. My custom cell has only two labels in it, which I have positioned one on top of the other. The top label is a simple 1-liner. The bottom label I would like to contain longer messages, and need it to word-wrap to multiple lines while staying within my specified width.</p>
  
  <p>How do I achieve this?</p>
  
  <p>So far, I've tried explicitly setting the frame of the label to the dimensions that I want, but it does not word-wrap, if this is all I do. It just flows out of the cell horizontally. I then tried calling <code>sizeToFit</code>, within the <code>tableView:cellForRowAtIndexPath:</code> function, for this label, but it appears to word-wrap at a very small width - the text wraps after like two or three letters and then flows out of the cell vertically.</p>
  
  <p>I can't seem to figure out how to get the text within the label to wrap after a specified width. Any ideas?</p>
  
  <p>My custom cell class: <a href="https://github.com/ryancole/pound-client/blob/master/pound-client/views/MessageListCell.m" rel="nofollow noreferrer">https://github.com/ryancole/pound-client/blob/master/pound-client/views/MessageListCell.m</a></p>
  
  <p>The <code>cellForRowAtIndexPath</code> function: <a href="https://github.com/ryancole/pound-client/blob/master/pound-client/controllers/MessageListViewController.m#L62-L84" rel="nofollow noreferrer">https://github.com/ryancole/pound-client/blob/master/pound-client/controllers/MessageListViewController.m#L62-L84</a></p>
  
  <p>Edit 1:</p>
  
  <p>To demonstrate what happened when I set <code>numberOfLines</code> to 0, for unlimited, I have attached a screenshots of that being called. It wraps after a few characters, instead of first taking up the specified width of the UILabel's frame. This is being set prior to called <code>sizeToFit</code>.</p>
  
  <p><a href="https://i.imgur.com/fT1S3.png" rel="nofollow noreferrer">
    <img src="https://i.imgur.com/fT1S3.png" height="300" />
  </a></p>