简体   繁体   English

NSMenuItem身高?

[英]NSMenuItem height?

How can I change the height of an NSMenuItem? 如何更改NSMenuItem的高度? When I change the font of a menu, an NSMenuItem automatically resizes to just fit the title, leaving no space above or below the title. 当我更改菜单的字体时,NSMenuItem会自动调整大小以适合标题,在标题的上方或下方不留空格。 It looks very cramped. 它看起来非常狭窄。

Looks like this: 看起来像这样:

在此输入图像描述

Want it to look like this: 希望它看起来像这样:

在此输入图像描述

I've tried a million tweaks related to the attributed title of the menu items, but to no avail. 我已经尝试了与菜单项的属性标题相关的百万次调整,但无济于事。 I also don't want to use the view property of the menu items because I want to keep the highlight. 我也不想使用菜单项的view属性,因为我想保持高亮显示。 Any other ideas? 还有其他想法吗?

Edit: This is what I'd like (more or less), but based on NSMenu, not redoing it from the ground up. 编辑:这是我想要的(或多或少),但基于NSMenu,而不是从头开始重做。

在此输入图像描述

You can set an empty 1-pixel wide image with the desired height: 您可以设置具有所需高度的空1像素宽图像:

NSImage *image=[[NSImage alloc]initWithSize:NSMakeSize(1,30)];

[menuItem setImage:image];

Obviously you end up with titles that are offset 1 pixel to the right, though that may be acceptable if uniformly applied. 显然,你最终会向右偏移1个像素的标题,但如果统一应用,这可能是可以接受的。

// you want height 100    
[menuItem setView:[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 100)]];

If you are looking for a re-implementation of NSMenu based upon NSWindow rather than the Carbon side of things check out JGMenuWindow : 如果您正在寻找基于NSWindowNSMenu的重新实现,而不是碳的一面,请查看JGMenuWindow

https://github.com/SquaredTiki/JGMenuWindow https://github.com/SquaredTiki/JGMenuWindow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM