tags:

views:

880

answers:

5

I want to set the images in my outline view to the system icons, just like on the left in the Finder. I want to get icons like Application, Documents, Desktop, etc. How do I do this?

+5  A: 

Use NSWorkspace's iconForFile: method

NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:@"/Applications/"];

edit:

take a look at these files, are they what you're after? Your question is a little hard to understand

$ ls /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Toolbar*FolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarAppsFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDesktopFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDocumentsFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDownloadsFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarLibraryFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarMovieFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarMusicFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarPicturesFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarPublicFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarSitesFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarUtilitiesFolderIcon.icns
cobbal
A: 

but I want to set the image of folder in the system dynamicly. just like applications documents,desktop , just like finder .

jin
This clarification belongs in the body of the question. You should edit your question instead of posting clarification as answers.
diciu
+2  A: 

There's a method in NSWorkspace that allows you to set custom icons to folders and files:

- (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath
    options:(NSWorkspaceIconCreationOptions)options

Sets the icon for the file or directory at the specified path.

diciu
A: 

This article on Creating icns Icon Files should cover what you want to do. There is also an article on creating an icon so that it looks similar to the standard folder icon, which is good for consistency. Hope that helps.

Of course, this isn't really programming related.

Jorge Israel Peña
A: 

Use -[NSWorkspace iconForFileType:], and pass constants from IconsCore.h (filtered through NSFileTypeForHFSTypeCode, of course).

Peter Hosey