Reputation: 2240
There are a UILabel in the center of the UIView, named nicknameLabel, and will append a gender image after the nicknameLabel.
But when the nicknameLabel has a lot of text, it will beyond the bounds of the UIView.
So, how to limit max width of UILabel?
BTW: I using the storyboard. Thanks.
Upvotes: 18
Views: 15900
Reputation: 3529
If you are using constraints then remove all constraints from you label.
Then again set frames of your label and if you want to make multiline label, then simply set the number of lines from 1 to 0 and increase the height of your label.
OR
If you want to fit your text within the label.You can simply enable Autoshrink property.
Upvotes: 2
Reputation: 3283
use following code
and set your width
in boundingRectWithSize
value.
CGSize itemTextSize = [@"Your Text" boundingRectWithSize:CGSizeMake(100, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont fontWithName:@"Helvetica Neue" size:12.5]} context:nil].size;
Upvotes: 4