Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line break in UILabel is being ignored on build

I'm trying to set up a three-line UILabel using XCode 4.2 and Interface Builder, building for iOS 5. After placing the UILabel, I've set the number of lines to 3 (this problem also occurs with number of lines set to 0), and I've used option-Return to break the lines properly in the text property. This all appears correctly in the storyboard preview in Interface Builder. The problem is when I build and run the app in the simulator, the line breaks are entirely ignored and the text just wraps in the UILabel's view wherever it needs to as though there were no line breaks in the text.

The obvious quick solution is to just set the text for the UILabel in code, or make three UILabels. No problem there. I'm just vexed by why this is happening when the label is set up purely in IB. Anyone encounter the same issue?

like image 963
Chris Avatar asked Dec 05 '11 16:12

Chris


2 Answers

This should probably be opened as a bug, however here is a workaround:

Instead of option-Return, use control-Return AND hit it twice (leaving a blank line between the rows of text in the storyboard). It will then display properly both in the storyboard, and on the device.

like image 158
lnafziger Avatar answered Nov 17 '22 16:11

lnafziger


By using this property of label,

label.lineBreakMode=UILineBreakModeCharacterWrap;
label.numberOfLines=0;

We can add a a bunch of text. See below screenshot.

enter image description here

like image 28
Vineesh TP Avatar answered Nov 17 '22 15:11

Vineesh TP