Re: newbie question - number of lines a text string wraps to
Re: newbie question - number of lines a text string wraps to
- Subject: Re: newbie question - number of lines a text string wraps to
- From: Jens Alfke <email@hidden>
- Date: Tue, 20 Apr 2010 11:52:44 -0700
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 (email@hidden)
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:
This email sent to email@hidden