2013-06-04 143 views
2

我想设置NSSegmentedControl背景图像不是图标image.I子类NSSegmentedCell并重写drawSegment: inFrame: withView:函数。但这种方法很糟糕。我该怎么做?如何设置NSSegmentedControl背景图片?

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

回答

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中正确设置了分段控件的单元类?

+0

+1我想你的答案足以解决问题。 –

+0

我想设置半直角暗色或浅色背景图像,而不仅仅是将图像添加到背景。 – gohamgx

+1

从原来的问题中不清楚。请更新问题以解释实际问题。 –