Closed mladjan closed 10 years ago
Did you dig in with a breakpoint on sizeToFit
and step into?
Did you try with methods dedicated to string size computations in my NSAttributedString
category instead of sizeToFit
?
Actually after re-reading your code this is probably normal if your text only fit in one line (see maybe related #3) and your font has a lineHeight
of 21, right?
I'm not sure using both sizeToFit
and AutoLayout is compatible (this assertion is not related to OHAttributedLabel
only, and is true for any UIView
). AutoLayout is supposed to adapt the frame of your views by applying constraints. Calling sizeToFit
also try to change this frame, but AutoLayout has always higher priority.
When you use AutoLayout, changing a view.frame
with [UIView setFrame:]
and such methods (which obviously sizeToFit
does as stated in the Apple documentation) won't work (won't do anything), because AutoLayout will apply its constraints and change the frame back by itself afterwards.
According to my tests I'm guessing it's not an OHAttributedLabel
issue but a problem understanding the way AutoLayout works and probably some inconsistency in your AutoLayout constraints.
Here is my code, and I don't know where I'm making a mistake. I don't use frames, I need only height so I can set height autolayout constraint from code.