我尝试阅读有关左侧源列表中的查找器中显示的图标的信息。我已经尝试过了NSFileManager
有以下选项
-
NSURLEffectiveIconKey
读取的图标与 Finder 中的图标不同
-
NSURLCustomIconKey
- 返回零
-
NSURLThumbnailKey
- 返回零
-
NSThumbnail1024x1024SizeKey
- 返回零
我设法使用 NSFileManager 读取所有已安装的设备,但我不知道如何读取与设备连接的图标?也许有人有任何想法或提示。
我也尝试使用
var image: NSImage = NSWorkspace.sharedWorkspace().iconForFile((url as! NSURL).path!)
但它返回相同的图像NSURLEffectiveIconKey
Thanks!
首先,查询 Finder 侧边栏中显示哪些卷的正确方法是使用 LSSharedFileList API。该 API 还提供了一种查询图标的方法:
LSSharedFileListRef list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteVolumes, NULL);
UInt32 seed;
NSArray* items = CFBridgingRelease(LSSharedFileListCopySnapshot(list, &seed));
CFRelease(list);
for (id item in items)
{
IconRef icon = LSSharedFileListItemCopyIconRef((__bridge LSSharedFileListItemRef)item);
NSImage* image = [[NSImage alloc] initWithIconRef:icon];
// Do something with this item and icon
ReleaseIconRef(icon);
}
您可以使用以下方式查询项目的其他属性LSSharedFileListItemCopyDisplayName()
, LSSharedFileListItemCopyResolvedURL
, and LSSharedFileListItemCopyProperty()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)