Finder Icon Overlay示例項目代表了一個小而非常基本但實際工作的示例,下面是答案。
https://github.com/lesnie/Finder-Icon-Overlay
我知道這是很老,但有些可能是主題(?)
下面是我這下豹(10.6)完成仍然有興趣。起初需要Finder的頭文件。使用類轉儲工具來獲取它。然後將您的代碼編寫爲SIMBL插件(請參閱文檔如何操作),調整一些方法。例如,要在ListView中的圖標上繪製圖標,必須重寫TIconAndTextCell方法的drawIconWithFrame:方法。
下面是方法混寫代碼:用我的方法方法:
+ (void) Plugin_load
{
Method old, new;
Class self_class = [self class];
Class finder_class = [objc_getClass("TIconAndTextCell") class];
class_addMethod(finder_class, @selector(FT_drawIconWithFrame:),
class_getMethodImplementation(self_class, @selector(FT_drawIconWithFrame:)),"[email protected]:{CGRect={CGPoint=dd}{CGSize=dd}}");
old = class_getInstanceMethod(finder_class, @selector(drawIconWithFrame:));
new = class_getInstanceMethod(finder_class, @selector(FT_drawIconWithFrame:));
method_exchangeImplementations(old, new);
}
我重寫 「drawIconWithFrame」 「FT_drawIconWithFrame:」。以下是此方法的示例實現。
- (void) FT_drawIconWithFrame:(struct CGRect)arg1
{
[self FT_drawIconWithFrame:arg1];
if ([self respondsToSelector:@selector(node)]) {
if ([[[[NSClassFromString(@"FINode") nodeWithFENode:[(TNodeIconAndNameCell *)self node]] fullPath] lastPathComponent] hasPrefix:@"A"])
[myPrettyIconOverlayImage drawInRect:NSMakeRect(arg1.origin.x, arg1.origin.y, arg1.size.height, arg1.size.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
}
本質上,它借鑑「myPrettyIconOverlayImage」過與文件名的文件圖標的每個以字母「A」開頭。這個邏輯取決於你。
注意這條線:[self FT_drawIconWithFrame:arg1];
這是如何調用'超'爲了得到正常的圖標和名稱等我知道,看起來很奇怪,像循環,但實際上它不是。然後換入SIMBL插件,安裝SIMBL並...運行。
由於獅子的變化,一些工作必須從頭開始(創建新的「Finder.h」文件,其中包含所有需要的聲明,找到合適的類別和方法來覆蓋),但這種技術仍然有效。
快樂黑客!
自從這篇文章已經有一段時間了,隨時可以使用10.6。你有沒有達到你想要的?你用Finder插件戰術去了嗎? – epologee 2011-03-22 11:53:58
有關獅子的任何更新? – Tony 2011-12-26 05:42:44
@LesNie下方鏈接到他的[Finder Icon Overlay](https://github.com/lesnie/Finder-Icon-Overlay)項目。鏈接以防其他人難以找到開源OS X Finder插件示例(就像我做的那樣)。 – pkamb 2015-01-12 23:35:37