anthony
anthony

Reputation: 41118

Ellipsizing an NSMenuItem's title to the width of the menu

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?

Upvotes: 2

Views: 833

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

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)

Upvotes: 1

Related Questions