Height of an NSAttributedString
Height of an NSAttributedString
- Subject: Height of an NSAttributedString
- From: Philip Dow <email@hidden>
- Date: Wed, 21 Dec 2005 16:09:14 +0100
This relates to a recent post on determining the width of a string to
resize a scroll view but deserves its own thread I think. At the
time, a piece of apple documentation was referred to which shows how
to calculate height for a given string:
http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/
Tasks/StringHeight.html#//apple_ref/doc/uid/20001809.
It is necessary to set up a text storage, text container and layout
manager, manually connect them, then grab the height using
usedRectForTextContainer or as John Stiles points out,
boundingRectForGlyphRange:inTextContainer: John also found a simpler
way to do this, creating a textview and then asking for the frame's
height after layouting out the associated glyphs.
This works fine for an NSString, however, when I attempt to do this
with an NSAttributedString containing multiple fonts as well as
graphics, I am unable to get an accurate total height, no matter how
I go about it. Has anyone had experience getting height for an
attributed string given a specific width? Is there something in the
layout manager I'm missing which is preventing it from taking into
account the graphics and various fonts?
-Phil
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden