iamnickpitoniak
iamnickpitoniak

Reputation: 227

How to display paragraph of text on Xcode storyboard?

I am attempting to display a paragraph of text to a ViewController with a UILabel, however the UILabel only stays on one single line even if I specify "0" lines (which should mean unspecified and flexible) in the UILabels attributes. What settings do I go about changing to allow the paragraph to automatically wrap the lines?

Upvotes: 4

Views: 9336

Answers (5)

Brad
Brad

Reputation: 1

Using UILabel setting 0 as the 'Lines' (the number of lines) in the attribute inspector makes it adapt accordingly. However you must tell Xcode when to break the line using 'Line Break' (also in the attribute inspector). Word wrap breaks the line at the last word that will fit in the text box for the width you have specified.

Upvotes: 0

Akshay Patel
Akshay Patel

Reputation: 157

UILabel.sizeToFit()

use this code and replace UILabel to your label object.

Upvotes: 1

Nour
Nour

Reputation: 1497

You have to set all 4 constraints (Top , Right , Bottom , Left ) for the label you want to make as a paragraph and set you maximum number of lines to 0 and it will work (This worked for me )

Upvotes: 0

Aamir
Aamir

Reputation: 16987

I think UITextView would be more appropriate, and best suites your requirement. The only thing you need to do is uncheck Editable to prevent user from editing displayed text. Any text greater than its size to be fit in would be scrollable, so you don't need to care about number of line etc.

Upvotes: 3

dr_barto
dr_barto

Reputation: 6065

As mentioned by @boidkan, you have to set both numberOfLines and lineBreakMode to get a multi-line display.

If you want to set the multi-line text statically in Interface Builder, you cannot directly type it into the attributes inspector (pressing enter will end editing instead of creating a newline); instead you have to type it in some text editor and copy-past it into IB.

Upvotes: 0

Related Questions