Search code examples
iphoneobjective-cioscore-text

CTFramesetterSuggestFrameSizeWithConstraints returns wrong height


i know there are posts about this, but none of them suggests something useful.. So my problem is that CTFramesetterSuggestFrameSizeWithConstraints returns height that is too small for my text, the longer the text the more of it get's cut. Code that i use to calculate height:

CGFloat widthConstraint = self.frame.size.width;
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);
CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter,CFRangeMake(0, 0),NULL,CGSizeMake(widthConstraint, 20000),NULL);
CGFloat suggestedHeight = suggestedSize.height;

So my question is what choise do i have? Maybe there are some workarounds? One of the solutions that i have found is to draw the text and only then find the height, but i don't know how to do that. So maybe someone has some solution to this?

Thanks i advance!!


Solution

  • Well after a very long time i've finally found out what's wrong.. After all the method works as intended and i think everyone else that says it's not on the internet have made some mistakes.. My mistake was when i draw text i've left some bad hardcoded values.. So if anyone has issues with CTFramesetterSuggestFrameSizeWithConstraints, double or tripple check your drawing code!