1
我想設置一個自定義的拖動圖標在NSTableView中使用。一切似乎都奏效,但由於我對Quartz缺乏經驗,我遇到了一個問題。NSImage透明度
- (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent *)dragEvent offset:(NSPointPointer)dragImageOffset
{
NSImage *dragImage = [NSImage imageNamed:@"icon.png"];
NSString *count = [NSString stringWithFormat:@"%d", [dragRows count]];
[dragImage lockFocus];
[dragImage compositeToPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.5];
[count drawAtPoint:NSZeroPoint withAttributes:nil];
[dragImage unlockFocus];
return dragImage;
}
基本上就是我希望做的是渲染透明度爲50%我的icon.png文件與一個NSString這顯示當前正在拖行數一起。我看到的問題是我的NSString呈現低透明度,但不是我的圖標。
這樣做更有意義。謝謝。 – ndg 2010-05-20 11:29:52
此外,['compositeToPoint:fromRect:operation:fraction:'is deprecated](http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/DeprecationAppendix/AppendixADeprecatedAPI.html# // apple_ref/OCC/instm/NSImage中/ compositeToPoint:fromRect:操作:分數:)。改用'drawAtPoint:fromRect:operation:fraction:'代替。 – 2010-05-21 10:10:34
好抓;我已經把這個消除了。 – Wevah 2010-05-21 13:29:11