how to determine pixel width of a string in a text field
how to determine pixel width of a string in a text field
- Subject: how to determine pixel width of a string in a text field
- From: Donald Hall <email@hidden>
- Date: Fri, 14 Feb 2003 22:04:32 -0700
Occasionally some of the path names I want to appear in a text field
are too long for the field. I had hoped that right justifying the
field would cause the (more interesting) end parts of the path to
appear in the field and cut off the names of directories higher in
the path on the left. Unfortunately, this does not seem to be the
case. If the string is too long to fit in a text field, it is always
the right end that gets cut off, regardless of justification. The
only thing I could see to do would be to calculate the pixel width of
the string and display only that part of the string that would fit
into the text field.
It looks like I should be using the AppKit NSStringAdditions methods
sizeWithAttributes: and drawInRect:withAttributes: However, I'm not
sure what to do about defining the attributes. Presumably the
attributes dictionary will need at least one entry, for the key
NSFontAtrributeName. I am only using the default system font. How do
I specify this? Is there a constant defined somewhere, or must I
explicitly create an NSFont object for Helvetica 12 point (assuming
that is the right one)?
Thanks,
Don
--
Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
email@hidden
http://www.appsandmore.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.