newbie question - number of lines a text string wraps to
newbie question - number of lines a text string wraps to
- Subject: newbie question - number of lines a text string wraps to
- From: "Paul J. Ascenzo" <email@hidden>
- Date: Mon, 19 Apr 2010 14:55:57 -0400
Hello all!
If this question doesn't belong on this list, please let me know, and
I'll try elsewhere - thanks!
WHAT I NEED:
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?
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.
WHAT I'VE TRIED:
I've looked pretty much everywhere in the Apple Docs and sample code
examples. I've gotten as far as finding an instance method in the
TextContainer class called usedRectForTextContainer. But I couldn't
figure out how to get the Text Container for a given NSTextField. So I
created a dummy (non visible) Text Container and Text Storage and
Layout Manager to match the NSTextField and asked it, thru
usedRectForTextContainer, to tell me how big a rect I need to display
the string of text.
WHAT DOESN'T YET WORK FOR ME:
The results from usedRectForTextContainer aren't actually matching the
size needed to display the text (the resulting rect is not tall
enough, but not by a consistent factor). I think I'm probably not
setting the font in the 'dummy' TextContainer to match the font in the
actual NSTextField.
Also, is there a way to get the Text Container for a given
NSTextField? (I can't find it anywhere, probably just looking in the
wrong places )
In any case, this has gotten way too complicated. Is there a simpler
way to do this?
I'll gladly supply the code I'm using if that would help.
Thank you in advance!!!
Paul
_______________________________________________
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