从苹果开发论坛开发者向我指出了正确的方向:https://devforums.apple.com/message/364824
这就是我想出了为NSPopUpButtonCell的子类,尊重来自IB的替代图像:
- (void)drawImageWithFrame:(NSRect)cellRect inView:(NSView *)controlView{
NSImage *image = self.image;
if([self isHighlighted] && self.alternateImage){
image = self.alternateImage;
}
//TODO: respect -(NSCellImagePosition)imagePosition
NSRect imageRect = NSZeroRect;
imageRect.origin.y = (CGFloat)round(cellRect.size.height*0.5f-image.size.height*0.5f);
imageRect.origin.x = (CGFloat)round(cellRect.size.width*0.5f-image.size.width*0.5f);
imageRect.size = image.size;
[image drawInRect:imageRect
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0f
respectFlipped:YES
hints:nil];
}
注意`respect```应该是`YES` – 2011-01-20 14:53:45
感谢您的提示:) – keegan3d 2011-02-04 07:34:49