Reputation: 71854
I am trying to assign a text to the UILabel
in UIViewController
and my text is :
Get As Many Questions Right As You Can! Get A Questionn Wrong. And You Will Loose A Life! Lose All Three Lives And It's Game Over!
But when I insert it into label it looks like :
I try to set Lines = 4 Like this way :
But its not working and my output should look like :
How can I achieve that? Is there any other way to do this?
Thanks In advance.
Upvotes: 0
Views: 97
Reputation: 1421
label.numberOfLines = 0;
to allow for any number of lines.\n
where you need a line-break.Update the label size to match the text size:
CGSize labelSize = [label.text sizeWithFont:label.font constrainedToSize:label.frame.size lineBreakMode:label.lineBreakMode];
label.frame = CGRectMake( label.frame.origin.x, label.frame.origin.y, label.frame.size.width, labelSize.height);
Upvotes: 0
Reputation: 2994
Option 1:-
Add it to a TextView instead of a UILabel
Option 2:-
Change the number of lines in your UILabel to 0, set the auto layout constraints properly and set preferredMaxLayoutWidth as follows:-
lbl.preferredMaxLayoutWidth = self.view.bounds.width
Upvotes: 1