Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 为NSSegmentedControl着色。。。怎样?_Macos_Cocoa_Nssegmentedcontrol - Fatal编程技术网

Macos 为NSSegmentedControl着色。。。怎样?

Macos 为NSSegmentedControl着色。。。怎样?,macos,cocoa,nssegmentedcontrol,Macos,Cocoa,Nssegmentedcontrol,我有一个NSSegmentedControl,在用户进入向导的下一阶段之前,必须选择该控件。我可以禁用“下一步”按钮,强制用户猜测缺少了什么,但如果用户在未选择控件上的选项的情况下按下“下一步”,我希望将控件闪烁为红色,如色调或边框,以引起注意 我在谷歌上找不到一个页面告诉我怎么做。用可可粉可以做到吗?如何为一个NSSegmentedControl执行此操作 我在中使用着色分段控件。这里的目的不是要引起人们对控件的注意,而是让它与彩色导航栏融合在一起。右上角 我没有从头开始绘制分段控件,而是将标

我有一个
NSSegmentedControl
,在用户进入向导的下一阶段之前,必须选择该控件。我可以禁用“下一步”按钮,强制用户猜测缺少了什么,但如果用户在未选择控件上的选项的情况下按下“下一步”,我希望将控件闪烁为红色,如色调或边框,以引起注意


我在谷歌上找不到一个页面告诉我怎么做。用可可粉可以做到吗?如何为一个
NSSegmentedControl
执行此操作

我在中使用着色分段控件。这里的目的不是要引起人们对控件的注意,而是让它与彩色导航栏融合在一起。右上角

我没有从头开始绘制分段控件,而是将标准实现绘制到NSImage中,然后再绘制到视图中

同样的原理也可以用来引起对控件的注意。无论何时更改色调颜色,都需要调用setNeedsDisplay

@interface TintedSegmentedCell : NSSegmentedCell
{
    NSMutableDictionary *_frames;
}

@end


@implementation TintedSegmentedControl

@synthesize tintColor = _tintColor;

- (void)dealloc
{
    [_tintColor release], _tintColor = nil;

    [super dealloc];
}

+ (Class)cellClass
{
    return [TintedSegmentedCell class];
}

@end


@implementation TintedSegmentedCell

- (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView:(NSView *)controlView
{
    [_frames setObject:[NSValue valueWithRect:frame] forKey:[NSNumber numberWithInteger:segment]];

    [super drawSegment:segment inFrame:frame withView:controlView];
}

- (void)drawWithFrame:(NSRect)frame inView:(NSView *)view
{
    if ([view isKindOfClass:[TintedSegmentedControl class]]) {
        NSColor *tintColor = [(TintedSegmentedControl*)view tintColor];

        if (tintColor != nil) {
            NSRect bounds = frame;

            bounds.origin.x = 0;
            bounds.origin.y = 0;

            NSSize size = bounds.size;
            NSImage *image = [[[NSImage alloc] initWithSize:size] autorelease];

            NSInteger segmentCount = [self segmentCount];
            NSMutableDictionary *frames = [NSMutableDictionary dictionaryWithCapacity:segmentCount];

            _frames = frames;

            [image lockFocus];
            {
                [super drawWithFrame:bounds inView:view];
            }
            [image unlockFocus];

            NSImage *tintedImage = [[image hh_imageTintedWithColor:[NSColor blackColor]] hh_imageTintedWithColor:tintColor];

            [tintedImage drawInRect:frame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];

            NSImage *overlayImage = [[[NSImage alloc] initWithSize:size] autorelease];

            [overlayImage lockFocus];
            {
                _frames = nil;

                for (NSInteger segment = 0; segment < segmentCount; segment++) {
                    NSRect frameRect = [[frames objectForKey:[NSNumber numberWithInteger:segment]] rectValue];

                    [self drawSegment:segment inFrame:frameRect withView:view];
                }
            }
            [overlayImage unlockFocus];

            [overlayImage drawInRect:frame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];

            return;
        }
    }

    [super drawWithFrame:frame inView:view];
}

@end
@接口TintedSegmentedCell:NSSegmentedCell
{
NSMutableDictionary*_帧;
}
@结束
@实现着色分段控制
@合成tintColor=\u tintColor;
-(无效)解除锁定
{
[[u tintColor release],[u tintColor=nil;
[super dealoc];
}
+(类)单元类
{
返回[TintedSegmentedCell类];
}
@结束
@实现TintedSegmentedCell
-(void)drawSegment:(NSInteger)段下:(NSRect)带视图的框架:(NSView*)控制视图
{
[\u frames setObject:[NSValue valueWithRect:frame]forKey:[NSNumber numberWithInteger:segment];
[super drawSegment:segment inFrame:frame withView:controlView];
}
-(无效)drawWithFrame:(NSRect)查看中的帧:(NSView*)视图
{
if([view isKindOfClass:[TintedSegmentedControl类]]){
NSColor*tintColor=[(TintedSegmentedControl*)查看tintColor];
如果(tintColor!=零){
NSRect界限=帧;
bounds.origin.x=0;
bounds.origin.y=0;
NSSize size=bounds.size;
NSImage*image=[[[NSImage alloc]initWithSize:size]autorelease];
NSInteger segmentCount=[self segmentCount];
NSMutableDictionary*frames=[NSMutableDictionary Dictionary WithCapacity:segmentCount];
_帧=帧;
[图像锁定焦点];
{
[super drawWithFrame:bounds inView:view];
}
[图像解锁焦点];
NSImage*TinteImage=[[image hh_imageTintedWithColor:[NSColor blackColor]]hh_imageTintedWithColor:TintedColor];
[tintedImage drawInRect:frame fromRect:NSZeroRect操作:NSCompositeSourceOver分数:1.0];
NSImage*overlayImage=[[NSImage alloc]initWithSize:size]自动释放];
[叠加图像锁定焦点];
{
_帧=零;
对于(NSInteger段=0;段<段计数;段++){
NSRect frameRect=[[frames objectForKey:[NSNumber numberWithInteger:segment]]rectValue];
[self-drawSegment:segment inFrame:frameRect withView:view];
}
}
[叠加图像解锁焦点];
[overlayImage drawInRect:frame fromRect:NSZeroRect操作:NSCompositeSourceOver分数:1.0];
返回;
}
}
[super drawWithFrame:frame inView:view];
}
@结束