Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在NSPopUpButton中显示文件夹_Objective C_Macos_Directory_Nspopupbutton - Fatal编程技术网

Objective c 在NSPopUpButton中显示文件夹

Objective c 在NSPopUpButton中显示文件夹,objective-c,macos,directory,nspopupbutton,Objective C,Macos,Directory,Nspopupbutton,我想在我的NspupButton中显示带有图标的文件夹。用于选择文件路径的弹出窗口很常见。我是新用户,不能发布图片。你可以在U Torrent->preferences->目录中看到这一点 请提供详细的答案,因为我在这方面是全新的 非常感谢并抱歉我的英语不好对于菜单中的每个NSMenuItem,您需要设置相应的图像,请致电 简而言之,您需要准备菜单项,将其附加到菜单,然后将菜单项附加到弹出按钮,如下所示: NSPopUpButton *yourButton = [[NSPopUpButton a

我想在我的NspupButton中显示带有图标的文件夹。用于选择文件路径的弹出窗口很常见。我是新用户,不能发布图片。你可以在U Torrent->preferences->目录中看到这一点

请提供详细的答案,因为我在这方面是全新的


非常感谢并抱歉我的英语不好

对于菜单中的每个
NSMenuItem
,您需要设置相应的图像,请致电

简而言之,您需要准备菜单项,将其附加到菜单,然后将菜单项附加到弹出按钮,如下所示:

NSPopUpButton *yourButton = [[NSPopUpButton alloc] init];
NSMenu *yourMenu = [[NSMenu alloc] init];

NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"some label" action:nil keyEquivalent:@""];
NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile:@"yourFilePath"];
[iconImage setSize:NSMakeSize(16,16)];

[menuItem setImage:iconImage];
[yourMenu insertItem:menuItem atIndex:0];
[yourButton setMenu:yourMenu];
请注意,在
NSWorkspace
中使用了,它允许您显示查找器中使用的相同图标

有关更多示例,您可以查看Apple提供的以下示例代码: