title: UILineBreakModeWordWrap (or NSLineBreakByWordWrapping) stop from splitting word across 2 lines
body: <p>I am trying to work out the biggest font size for a string that will fit within a defined rectangle. Now I have found many other posts that state how to do it including:</p>
  <p><a href="https://stackoverflow.com/questions/3520855/resizing-uilabel-to-fit-with-word-wrap">Resizing UILabel to fit with Word Wrap</a></p>
  <p><a href="https://stackoverflow.com/questions/6198084/resize-catextlayer-to-fit-text-on-ios?rq=1">Resize CATextLayer to fit text on iOS</a></p>
  <p><a href="https://stackoverflow.com/questions/1204000/iphone-uilabel-sizewithfont/3599071#3599071">iPhone UILabel sizeWithFont:</a></p>
  <p><a href="https://stackoverflow.com/questions/15118623/which-characters-does-nslinebreakbywordwrapping-break-on">Which characters does NSLineBreakByWordWrapping break on?</a></p>
  <p>Now these are great and tell me how to get the biggest font size. However when using the method &quot;sizeWithFont:constrainedToSize:lineBreakMode:&quot; with a line break of (UILineBreakModeWordWrap or NSLineBreakByWordWrapping) it is actually splitting large words across multiple lines.</p>
  <p><strong>Isn't UILineBreakModeWordWrap (or NSLineBreakByWordWrapping) suppose to mean that words don't 'split' over more than one line.</strong> I'm happy for multiple words being on multiple lines, however I don't want a single word to be split across two. If UILineBreakModeWordWrap can't do this, is there something else that can?</p>
  <p>Below is the code I use to determine the biggest possible font size: (text is @&quot;australia&quot;)</p>
  <pre><code>-(UIFont *)GetFontSizeForText:(NSString *)text inRect:(CGRect)rect {
      BOOL notFit = YES;
      CGSize textSize;
      CGFloat tmpFontSize = TEMPLATE_DEFAULT_FONT_SIZE;
      UIFont *tmpFont;    
  
      CGSize maxSize = CGSizeMake(rect.size.width, MAXFLOAT);
  
      while (notFit) {
          tmpFont = [UIFont fontWithName:TEMPLATE_DEFAULT_FONT_NAME size:tmpFontSize];
          textSize = [text sizeWithFont:tmpFont constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap];
  
          if (textSize.height &gt; rect.size.height) {
              tmpFontSize -= 1.0;
              if (tmpFontSize &lt; 2.0) {
                  break;
              }
          } else {
              notFit = NO;
          }
      }
  
      return tmpFont;
  }
  </code></pre>
  <p>Below is an image link that shows what happens when using the above function to work out a font size. The 'yellow' box is the biggest size. The purple box is the actual CATextLayer being rendered using the calculated font size. The 'AUSTRALIA' text above these box's is a UILabel that I put on there with interface builder at the same font size.</p>
  <p><a href="http://www.connstructstudios.com.au/externalimages/multilines.png" rel="nofollow noreferrer">http://www.connstructstudios.com.au/externalimages/multilines.png</a></p>