如何设置NSSegmentedControl背景图像?

时间:2013-06-04 08:01:31

标签: objective-c macos cocoa nssegmentedcontrol

我想设置NSSegmentedControl背景图片而不是图标图像。我将NSSegmentedCell子类化并重写drawSegment: inFrame: withView:函数。但是这样做不好。我该怎么做?< / p>

更新: 我想设置半直的深色或浅色背景图像。

1 个答案:

答案 0 :(得分:1)

子类化和覆盖drawSegment: inFrame: withView工作正常

- (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView:(NSView *)controlView
{
    NSImage* image = [NSImage imageNamed:NSImageNameBonjour];
    [image drawInRect:frame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
    [super drawSegment:segment inFrame:frame withView:controlView];    
}

你还尝试了什么?
您是否在Interface Builder中正确设置了分段控件的单元类?