Set button image to Finder icon

How to set NSButton image to Finder icon (programmatically) ?

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

Any help would be appreciated!

+4
source share
2 answers

Alternative 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 enable <CoreServices/CoreServices.h> so that the compiler knows about kFinderIcon .

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

Source: https://habr.com/ru/post/1337028/


All Articles