Is there a way to have multiple lines of text in UILabel
like in the UITextView
or should I use the second one instead?
Property Value True if the label control is multiline; otherwise, False. A multi-line label control renders the label's text on more than one line. If the WordWrap property is set to True, long lines will be wrapped to the following line.
If you set numberOfLines to 0 (and the label to word wrap), the label will automatically wrap and use as many of lines as needed. If you're editing a UILabel in IB, you can enter multiple lines of text by pressing option + return to get a line break - return alone will finish editing.
Set the line break mode to word-wrapping and the number of lines to 0
:
// Swift textLabel.lineBreakMode = .byWordWrapping textLabel.numberOfLines = 0 // Objective-C textLabel.lineBreakMode = NSLineBreakByWordWrapping; textLabel.numberOfLines = 0; // C# (Xamarin.iOS) textLabel.LineBreakMode = UILineBreakMode.WordWrap; textLabel.Lines = 0;
Restored old answer (for reference and devs willing to support iOS below 6.0):
textLabel.lineBreakMode = UILineBreakModeWordWrap; textLabel.numberOfLines = 0;
On the side: both enum values yield to 0
anyway.
In IB, set number of lines to 0 (allows unlimited lines)
When typing within the text field using IB, use "alt-return" to insert a return and go to the next line (or you can copy in text already separated out by lines).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With