Reputation: 11297
I have a UILabelView within a RoundedRectView. The UILabelView is supposed to show a dynamically generated text string with new lines in it.
The problem is that the UILabel still shows the text as "blahblahbla..." and does not seem to show the text over multiple lines. The only exception is when I do a "sizeToFit" function call however at that time, the text no longer appears in the center of the parent view. I have the UILabelView number of lines to be 0 and also have increased the frame of the parent view (RoundedRectView)
What can I do to get past this?
Here is my code:
CGRect frame = [self.messageView frame]; //get the frame size of parent view
self.messageView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, (lineHeight * count)); //increase it to fit the text
self.messageLabel.text = message;
[self.messageView setNeedsDisplay];
// [self.messageLabel sizeToFit]; this fixes the multiple line issue but now label is not centered in parent view
Upvotes: 0
Views: 1595
Reputation: 29767
Set numberOfLines
to 0, lineBreakMode
to UILineBreakModeWordWrap
, adjustsFontSizeToFitWidth
to NO. Check if your text contains '\n'.
Upvotes: 3