开发者

Set Button Image to Finder Icon

开发者 https://www.devze.com 2023-02-06 12:18 出处:网络
How would I set a NSButton\'s image to the Finder icon (programmatically)开发者_如何学运维 ? I\'m trying to do this in Objective-C/Cocoa (Mac)

How would I set a NSButton's image to the Finder icon (programmatically)开发者_如何学运维 ?

I'm trying to do this in Objective-C/Cocoa (Mac)

Any help would be appreciated!


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


Alternate solution:

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

You may need to include <CoreServices/CoreServices.h> in order for the compiler to know about kFinderIcon.

0

精彩评论

暂无评论...
验证码 换一张
取 消