gpt4 book ai didi

objective-c - 如何设置 NSSegmentedControl 背景图像?

转载 作者:行者123 更新时间:2023-12-03 16:41:47 25 4
gpt4 key购买 nike

我想设置 NSSegmentedControl 背景图像而不是图标图像。我对 NSSegmentedCell 进行子类化并重写 drawSegment: inFrame: withView:功能。但这效果不好。我该怎么做?

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

最佳答案

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

关于objective-c - 如何设置 NSSegmentedControl 背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16912625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com