Set Button Image to Finder Icon
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
.
精彩评论