I`m working on an iOS project but when I updated to iOS 9 I had some problem with multiline in UILabels. I'm using Autolayout.
Anybody knows how to do it in iOS 9 ?
I tried different ways such as:
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
(from other similar question) but it did not work.
This is my logic to show multilines:
IB config:
I update this value programmatically:
- (void)configureLabelsMaxLayoutWidth
{
[self.view layoutIfNeeded];
self.titleLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.titleLabel.frame);
}
I call this method on the viewWillAppear
By setting numberOfLines
to 0
you're telling the label to be multiline, however there may be other factors disabling multilines. Are you using autolayout? If so, that problem may be that the labels Content Compression Resistance Priority
is too low, try setting it to Required
or 1000
.
The content compression resistance tells the view engine at what priority your label can shrink. Setting it to required forces it to not shrink.
In Interface Builder, simply select the label, tap Size Inspector
(the little ruler) and then change it to 1000.
Or, in code, the equivalent would be:
[label setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
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