Re: Space Required By Text
Re: Space Required By Text
- Subject: Re: Space Required By Text
- From: John Hörnkvist <email@hidden>
- Date: Wed, 30 May 2001 20:54:42 +0200
On Wednesday, May 30, 2001, at 06:51 PM, David Remahl wrote:
Hi.
I have a text, which I would like to display in a text field. I would
like to size the text field on run time to fit exactly the text. The
text is line-broken by hard breaks, and occupies many lines, and
approximately 80 columns. I would like to know the rect in which the
text exactly fits using my font attributes.
I think this could be made using a constellation of NSTextContainer,
NSLayoutManager, NSTextStorage and possible other classes, but I don't
see how they fit.
For an NSAttributedString you can just do [string size].
For an NSString you can do [string sizeWithAttributes:myAttributes],
where myAttributes is a dictionary.
Check NSStringDrawing.h in the AppKit.
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com