Note that there are some explanatory texts on larger screens.

plurals
  1. POLine breaks not working in UILabel
    primarykey
    data
    text
    <p>I'm loading some help text from a plist and displaying the same in the form of UILabels housed in a UIScrollView. Portion of the code follows:</p> <p><code></p> <pre><code> UILabel *sectionDetailLabel = [[[UILabel alloc] initWithFrame:CGRectMake(34, myOriginForThisSection, 286, 20)] autorelease]; sectionDetailLabel.backgroundColor = [UIColor clearColor]; sectionDetailLabel.numberOfLines = 0; sectionDetailLabel.font = [UIFont systemFontOfSize:12]; sectionDetailLabel.textColor = [UIColor blackColor]; sectionDetailLabel.textAlignment = UITextAlignmentLeft; sectionDetailLabel.lineBreakMode = UILineBreakModeWordWrap; [baseScrollView addSubview:sectionDetailLabel]; [sectionDetailLabel setText:myStringForThisSection]; [sectionDetailLabel sizeToFit]; </code></pre> <p></code></p> <p>While any 'long' text is getting wrapped into multiple lines correctly, I'm unable to manually insert any line-breaks using newline '\n' characters in 'myStringForThisSection'. I only see the characters '\' and 'n' printed in the UILabel wherever I wanted the line-break, instead.</p> <p>I looked this up and the general consensus seemed to be that setting numberOfLines to 0, setting the lineBreakMode to a valid value and invoking sizeToFit (or setting the frame of the UILabel based on sizeWithFont:) should do. All of which I seem to be doing in the code above - and works perfectly when fitting long strings of unknown length into multiple lines on the UILabel. So what could be missing here?</p> <p>Note: All the variables used - baseScrollView, myStringForThisSection and myOriginForThisSection - were loaded before the above code began executing, and work fine.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload