In CoreText it is easy ask: "for a given rectangle how much of this attributed string will fit?".
CTFrameGetVisibleStringRange(rect).length
Will return where in the string the next run of text should begin.
My question is: "given an attributed string and a width, what rect height do I need to completely bound the attributed string?".
Does the CoreText framework provide tools to do this?
Thanks,
Doug
What you need is
CTFramesetterSuggestFrameSizeWithConstraints()
, you can use it like so:EDIT
As ARC releases only Objective-C objects, and CoreText deals with C, very likely you can have a memory leak here. If your
NSAttributedString
is small and you do it once, you shouldn't have any bad consequences. But in a case you have a loop to calculate, let's say, 50 heights of big/complexNSAttributedString
s, and you don't release theCTFramesetterRef
, you can have serious memory leaks. Check the tutorial linked for more information on memory leaks and debugging with instruments.So the solution for this problem is to add
CFRelease(frameSetter);