I am working on a project that has to support both iOS6 and iOS7. My problem is it works different on different systems. I'm trying to create UILabel with number of lines equal to 2, but when I set it's line break mode to NSLineBreakByTruncatingTail it works different.
Explanation (numberOfLines = 2, text = @"long teeexxxttt"):
iOS7 iOS6
NSLineBreakByWordWrapping
---------- ----------
|long | |long |
|teeeexxxtt| |teeeexxxtt|
---------- ----------
NSLineBreakByTruncatingTail
---------- ----------
|long | |long te...|
|teeeexx...| | |
---------- ----------
^ ^
| |
correct incorrect - shows only one line
How do I fix it?
I know this is an old question, but I recently had the same problem. I found that with constraints I had to set the preferred width to get the ellipsis to behave properly:
yourLabel.preferredMaxLayoutWidth = width;
UILable.preferredMaxLayoutWidth
The problem is iOS6 and prior won't update multiline UILabels with custom UIFont and NSLineBreakByTruncatingTail, but you can archive the same result by using autoresizing or autolayout.
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