daven11
daven11

Reputation: 3025

Any way to (easily) determine the minimum width required to format a Framesetter?

If I have a framesetter that I've initialised with a string like so

CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);

I'd like to find the minimum width to display the largest string in the frame. Is there an easy way to do this? I can do it by iterating over the lines and runs and calculating it from there, but it seems like something that would have a method since it would calculate this internally.

I tried

CGSize sz = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(1, CGFLOAT_MAX), NULL);

but it just returns a constant size which seems to be the width of a single glyph.

tia

Upvotes: 0

Views: 109

Answers (1)

MrO
MrO

Reputation: 725

If you're looking for widths, you should pass CGFLOAT_MAX for the width in your CGSizeMake to indicate that width is unconstrained.

Generally speaking, to find a height for a given width, pass CGSizeMake(myWidth, CGFLOAT_MAX), and to find a width for a single line of text, pass CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX).

Upvotes: 1

Related Questions