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?
我想将大纲视图中的图像设置为系统图标,就像在Finder左侧一样。我想获得应用程序,文档,桌面等图标。我该怎么做?
4 个解决方案
#1
There's a method in NSWorkspace that allows you to set custom icons to folders and files:
NSWorkspace中有一个方法,允许您将自定义图标设置为文件夹和文件:
- (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath
options:(NSWorkspaceIconCreationOptions)options
Sets the icon for the file or directory at the specified path.
设置指定路径上的文件或目录的图标。
#2
Use NSWorkspace's iconForFile: method
使用NSWorkspace的iconForFile:方法
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
#3
Use -[NSWorkspace iconForFileType:]
, and pass constants from IconsCore.h (filtered through NSFileTypeForHFSTypeCode
, of course).
使用 - [NSWorkspace iconForFileType:],并从IconsCore.h传递常量(当然,通过NSFileTypeForHFSTypeCode过滤)。
#4
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.
这篇关于创建icns图标文件的文章应该涵盖你想要做的事情。还有一篇关于创建图标的文章,使其看起来与标准文件夹图标类似,这有利于保持一致性。希望有所帮助。
Of course, this isn't really programming related.
当然,这与编程无关。
#1
There's a method in NSWorkspace that allows you to set custom icons to folders and files:
NSWorkspace中有一个方法,允许您将自定义图标设置为文件夹和文件:
- (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath
options:(NSWorkspaceIconCreationOptions)options
Sets the icon for the file or directory at the specified path.
设置指定路径上的文件或目录的图标。
#2
Use NSWorkspace's iconForFile: method
使用NSWorkspace的iconForFile:方法
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
#3
Use -[NSWorkspace iconForFileType:]
, and pass constants from IconsCore.h (filtered through NSFileTypeForHFSTypeCode
, of course).
使用 - [NSWorkspace iconForFileType:],并从IconsCore.h传递常量(当然,通过NSFileTypeForHFSTypeCode过滤)。
#4
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.
这篇关于创建icns图标文件的文章应该涵盖你想要做的事情。还有一篇关于创建图标的文章,使其看起来与标准文件夹图标类似,这有利于保持一致性。希望有所帮助。
Of course, this isn't really programming related.
当然,这与编程无关。