Ios – NSAttributedString ignores Autoshrink and numberOfLines for UILabel (iOS 6)

iosiphonensattributedstringobjective cuilabel

I have UILabel with
number of lines = 2
system font size = 15
minimum font size = 8
Line break mode – Truncate tail

When I set long text which have type NSString for UILabel it works fine and shows multiline text (scaled if needed).
When I am trying to set text with type NSAttributedString it ignores minimum font size and Autoshrink so I see one line text with maximum font size.

Is it possible to solve this problem

Looks something like this (Label size is const)

-----------------------
| normal NSString  Text|
| very  very  long ... | 
-----------------------

---------------------------
|NSAttributedString tex...|
---------------------------

Best Answer

I found a way to do this:

label.adjustsFontSizeToFitWidth = true
label.attributedText = attributedString
label.lineBreakMode = .ByTruncatingTail // this did the trick!

It only works if the third line is set after setting the attributed string. It seems like the attributed string overrides line break behavior when set (among other things).

Related Topic