On Apr 19, 2010, at 11:55 AM, Paul J. Ascenzo wrote:

> I'm looking to find out how many lines a given string of text will wrap to in 
> a given NSTextField. in other words, once I know the string and the size of 
> the field it is going into, how do I find out how many lines the system will 
> wrap the text to?

It sounds like what you really want to know is the height of the text in 
pixels. (Or points, really.) The number of lines isn’t useful for measuring 
that, because lines can vary in height.

> I want this because I'd like to size the NSTextField to fit snugly around the 
> text. And the text string will change often, so I need to resize often.

This is easier to do with an NSTextView. After installing the new text, you can 
look at the text view’s bounds to see how tall it is. (Remember that the text 
view is wrapped in an NSScrollView, so you actually need to resize the scroll 
view.)

The reason it’s harder with an NSTextField is because, for performance reasons, 
the text field doesn’t actually do any of the text display or layout. Rather, 
it uses a shared NSTextView called the field editor. Doing text-intensive stuff 
with an NSTextField involves attaching and detaching the field editor, which is 
kind of messy.

—Jens_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to