如何更改 NSPopUpButton 中 NSMenuItem 的简短显示形式?

发布于 2024-11-28 07:57:15 字数 373 浏览 0 评论 0原文

我有一个 NSPopUpButton ,其中有一个很长的项目菜单,其中一些项目非常宽 - 比按钮的闭合宽度更宽。一些菜单项标题如下所示:

“一个非常长的名称的开头不是那么有趣(重要信息)”

当菜单关闭时,它显示为:

“一个真正的长名称的开始”长名称不是...”

我希望它显示为:

“真正的l...(重要信息)的开始”

我不知道NSPopUpButton如何正在创建那个省略号。 NSMenuItem 上是否调用了选择器? NSPopUpButton 或 NSMenu 是否以某种方式处理该问题?

我需要子类化哪个类以及需要覆盖或实现哪个选择器?

非常感谢。

I have an NSPopUpButton with a long menu of items, some of which are quite wide - wider than the button's closed width. Some of the menu item titles are like so:

"Start of a really long name not that interesting (important info)"

When the menu is closed, this displays as:

"Start of a really long name not th..."

I'd like it to display as:

"Start of a really l... (important info)"

I can't figure out how NSPopUpButton is creating that ellipsis. Is there a selector being called on NSMenuItem? Does NSPopUpButton or NSMenu handle that somehow?

Which class do I need to subclass and which selector to I need to override or implement?

Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阳光下慵懒的猫 2024-12-05 07:57:15

这种机制称为截断。 Interface Builder 中有一个名为换行符的选项,它分组在控制组中。您可能正在寻找的设置称为“截断中间”,它将开始从菜单项的中间选取字母。

但请注意,这并不能完全解决您的问题,因为 (重要信息) 部分可能不是“…”之后唯一剩下的部分,而是 我的 Me…tem 的名称(重要)信息)。此外,您可能还会得到部分被截断的重要信息。但我认为只要重要信息是一些数字或几个字母,你就可以

也许向菜单项添加图像可能更适合您的需求(某种徽章)?也许属性字符串还有一个选项可以强制字母不被截断……但不确定。

This mechanism is called truncation. There is an option in Interface Builder called Line Breaks which is grouped in the Control group. The setting you're probably looking for is called Truncate Middle which will start picking letters from the middle of the menu item.

Note however that this won't solve your problem entirely as the (important info) part might not be the only one remaining after "…", but rather Name of my Me…tem (important info). Furthermore you might also end up with the important info partially truncated. But I figure you're fine as long as the important info is some number or a few letters.

Maybe adding an image to the menu item might suit your needs more (some sort of badge)? Maybe there is also an option for attributed strings to force letters to not be truncated… not sure however.

別甾虛僞 2024-12-05 07:57:15

法比安给了我我需要的线索。谢谢!

[[self cell] setLineBreakMode: NSLineBreakByTruncatingMiddle]

不过,如果有办法获得更细粒度的控制,那就更好了。有没有办法更精确地控制截断?

Fabian gave me the clue I needed. Thanks!

[[self cell] setLineBreakMode: NSLineBreakByTruncatingMiddle]

However, if there is a way to get finer-grained control, that would be even better. Is there a way to control the truncation more precisely?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文