views:

22

answers:

1

I want to programatically change an NSMenuItem's title, but ellipsize it so that this modification never causes the menu to increase in width. how can i do this?

+1  A: 

You have to do this yourself. NSString has some methods added by AppKit for determining the length of a string, given a certain font, etc. If you find the string is too long, remove a chunk from the middle, measure again, and keep doing that until the string is short enough.

However, this might be overkill, since NSMenuItem will "ellipsize" the title automatically (although this can result in super-wide menus)

Dave DeLong