I'm dynamically populating the title (UILabel). Sometime it's bit too long and IOS squeeze the font to fit in the width. Is there a way to do multiline with using same font size?
4 Answers
Set adjustsFontSizeToFitWidth
to NO and numberOfLines
to 0.
numberOfLines Docs
This property controls the maximum number of lines to use in order to fit the label’s text into its bounding rectangle. The default value for this property is 1. To remove any maximum limit, and use as many lines as needed, set the value of this property to 0.
If you constrain your text using this property, any text that does not fit within the maximum number of lines and inside the bounding rectangle of the label is truncated using the appropriate line break mode.
When the receiver is resized using the sizeToFit method, resizing takes into account the value stored in this property. For example, if this property is set to 3, the sizeToFit method resizes the receiver so that it is big enough to display three lines of text.
You may additionally want to specify the lineBreakMode
unless the default UILineBreakModeWordWrap
is suitable for what you want.

- 26,946
- 12
- 75
- 101
-
2Worth noting that `UILineBreakModeWordWrap` is deprecated since iOS 6.0, replaced by `NSLineBreakByWordWrapping` – mwfire May 06 '14 at 17:40
-
4No need to set `adjustsFontSizeToFitWidth` to `NO` - **Default is `NO`** – Hemang Jun 21 '14 at 10:54
Use UILabel
properties as below :
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;

- 2,768
- 3
- 35
- 61

- 61
- 1
- 2
Yes, you set the numberOfLines
to 0, and the .lineBreakMode
to UILineBreakModeWordWrap
in code, or the equivalents if your label is defined in IB.

- 118,105
- 32
- 252
- 268
I just used LineBreak mode to Truncate Tail and setNumberOfLines to 0 and its working for me. the label is of multiline now.

- 959
- 1
- 8
- 17
-
Set the Autoshrink to minimum font size. and check the tighten letter spacing. – Waqas Sep 15 '14 at 11:50
-
This is essential! Word wrap *doesn't* do it, you must set a truncate mode – Jonathan Crooke Mar 13 '15 at 19:23