Re: horizontal sizeToFit of NSTextView or NSTextField
Re: horizontal sizeToFit of NSTextView or NSTextField
- Subject: Re: horizontal sizeToFit of NSTextView or NSTextField
- From: Jack Repenning <email@hidden>
- Date: Mon, 21 Apr 2008 08:41:41 -0700
On Apr 20, 2008, at 11:37 AM, Manfred Schwind wrote:
Getting the height of a text for a given width is easy and I've done
that countless times.
Also getting the width of a string (layed out in one line if it has
no newlines) is no problem.
But I have a different problem. I try to give an easier explanation
of my problem:
I have a text view that has a height that can hold three lines of
text. Now I have one long string (without newlines). When putting
this string into the text view, the text is automatically wrapped
around. But maybe - for the initial width of the view - it will need
four (or more) lines instead of just three. Now I want to calculate
the optimal (minimum) width of the text view, to that the string is
wrapped around in just three (or less) lines.
Either I'm misunderstanding your question, or you're misunderstanding
the Geometries code. I think you want -widthForHeight:attributes:,
with the height specified for three lines (could just take it from
what IB sets for you, or first get a heightForWidth:reallyBig, then
triple that). The demo program has a -heightForWidth:attributes:
case, just flip it around. This code _does_ work for a multi-line
height, and does allow for correct wrapping, font changes in mid fly,
multibyte characters, and all the rest.
-==-
Jack Repenning
email@hidden
Project Owner
SCPlugin
http://scplugin.tigris.org
"Subversion for the rest of OS X"
_______________________________________________
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