title: iOS - Combine NSLineBreakByWordWrapping and NSLineBreakByTruncatingTail
body: <p><strong>What I need</strong></p>
  
  <p>I need to write some text to a PDF. The text itself can be any length, but I can only display 2 lines (by word wrapping) and should truncate the tail in the second line if the space isn't enough.</p>
  
  <p><strong>What I've tried</strong></p>
  
  <pre><code>NSMutableParagraphStyle *text = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
  text.lineBreakMode = NSLineBreakByTruncatingTail;
  </code></pre>
  
  <p>This way, the text goes only in the first line, and truncates at the end of the line.</p>
  
  <pre><code>NSMutableParagraphStyle *text = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
  text.lineBreakMode = NSLineBreakByWordWrapping;
  </code></pre>
  
  <p>This way, the text wraps to the second line, but if there's enough text for more lines, there's no truncating at the end of the second line.</p>
  
  <p>I need some way to combine these two behaviours.</p>
  
  <p><strong>What I've researched</strong></p>
  
  <p>I've found some questions about problems with word wrapping, but nothing like this.
  The nearest I've got was this:</p>
  
  <p><a href="https://stackoverflow.com/questions/15536260/nslinebreakbywordwrapping-on-first-line-but-nslinebreakbytruncatingtail-for-seco">NSLineBreakByWordWrapping on First Line but NSLineBreakByTruncatingTail For Second Line?</a></p>
  
  <p>But the problem there was different. In that question, the asker wants this behaviour but in a label, and he fixes the problem with some storyboard configuration that I've also used in other part of my project. But this question is about this behaviour in a PDF, using the <code>NSStringDrawingContext</code> <code>drawInRect</code> method.</p>
  
  <p>I'm using iOS 7 (actually just updated to 7.1, but the situation is the same in both).</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit - also, I've looked this link before asking, but with no help:</p>
  
  <p><a href="https://developer.apple.com/library/ios/documentation/cocoa/reference/ApplicationKit/Classes/NSParagraphStyle_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSLineBreakByWordWrapping" rel="nofollow noreferrer">https://developer.apple.com/library/ios/documentation/cocoa/reference/ApplicationKit/Classes/NSParagraphStyle_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSLineBreakByWordWrapping</a></p>