2013-06-04 140 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

從原來的問題中不清楚。請更新問題以解釋實際問題。 –