我最終編寫了一個NSImage類的類方法,它返回所需大小和所需顏色的模板圖像(基本上是自己做的,因爲我不認爲API提供了這種方法)。
+(NSImage *)templateImage:(NSString *)templateName
withColor:(NSColor *)tint
andSize:(CGSize)targetSize
{
NSImage *template = [NSImage imageNamed:templateName];
NSSize size = (CGSizeEqualToSize(targetSize, CGSizeZero)
? [template size]
: targetSize);
NSRect imageBounds = NSMakeRect(0, 0, size.width, size.height);
NSImage *copiedImage = [template copy];
[copiedImage setTemplate:NO];
[copiedImage setSize:size];
[copiedImage lockFocus];
[tint set];
NSRectFillUsingOperation(imageBounds, NSCompositeSourceAtop);
[copiedImage unlockFocus];
return [copiedImage autorelease];
}
來源
2011-06-09 11:50:43
Dov
你能發表一個截圖來展示問題嗎? – 2011-06-05 00:30:28