将按钮图像设置为Finder图标

时间:2011-01-25 17:26:28

标签: objective-c macos cocoa

如何将 NSButton的图像设置为 Finder图标(以编程方式)

我正在尝试在 Objective-C / Cocoa Mac

中执行此操作

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:8)

NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSImage *finderIcon = [workspace iconForFile:[workspace absolutePathForAppBundleWithIdentifier:@"com.apple.Finder"]];
[finderIcon setSize:NSMakeSize(128.0, 128.0)];
[yourButton setImage:finderIcon];

答案 1 :(得分:5)

替代解决方案:

NSWorkspace *wksp = [NSWorkspace sharedWorkspace];
NSImage *image = [wksp iconForFileType:NSFileTypeForHFSTypeCode(kFinderIcon)];
[image setSize:(NSSize){ 128.0f, 128.0f }];
[button setImage:image];

您可能需要包含<CoreServices/CoreServices.h>,以便编制者了解kFinderIcon