• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
how to determine pixel width of a string in a text field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: how to determine pixel width of a string in a text field
      • From: Henry McGilton <email@hidden>
  • Prev by Date: how do I change the Kind of my document?
  • Next by Date: AddressBook problems
  • Previous by thread: how do I change the Kind of my document?
  • Next by thread: Re: how to determine pixel width of a string in a text field
  • Index(es):
    • Date
    • Thread