Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想以编程方式更改 NSMenuItem 的标题,但将其省略,以便此修改不会导致菜单宽度增加。我怎样才能做到这一点?
你必须自己做。NSString 有一些 AppKit 添加的方法来确定字符串的长度,给定特定的字体等。如果你发现字符串太长,从中间删除一个块,再次测量,并继续这样做直到字符串变短足够。
然而,这可能是矫枉过正,因为NSMenuItem会自动“省略”标题(尽管这可能会导致超宽菜单)
NSMenuItem