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?
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.
By using this property of label,
label.lineBreakMode=UILineBreakModeCharacterWrap;
label.numberOfLines=0;
We can add a a bunch of text. See below screenshot.
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