NSPopUpButton Active Image

我想创建一个带有自定义活动图像的NSPopUpButton。我有两个图像,一个用于非活动,另一个用于活动。在界面构建器中,我设置了Image和Alt。 NSPopUpButton的图片。图像显示正确但当我单击按钮时,它显示标准的暗按钮状态而不是Alt。图片。 以下是界面构建器面板的屏幕截图:http://cl.ly/0D2c0Y2y0f1Z462d311X 如何设置NSPopUpButton以在单击时显示我的备用图像?     
已邀请:
来自Apple Dev论坛的开发人员向我指出了正确的方向: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];    
}
    

要回复问题请先登录注册