Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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 NSButton在drawRect中着色图像_Macos_Cocoa_Nsimage_Nsbutton_Nsbuttoncell - Fatal编程技术网

Macos NSButton在drawRect中着色图像

Macos NSButton在drawRect中着色图像,macos,cocoa,nsimage,nsbutton,nsbuttoncell,Macos,Cocoa,Nsimage,Nsbutton,Nsbuttoncell,我想在drawRect中着色我的按钮,但找不到正确的设置来着色图像 -按钮是无边框的,带有灰度图像,我想对其着色 在我的NSButton子类中: - (void)drawRect:(NSRect)dirtyRect{ if ([self.cell mouseDownFlags] == 0) { [[NSColor redColor] set]; } else { [[NSColor blackColor] set]; }

我想在drawRect中着色我的按钮,但找不到正确的设置来着色图像

-按钮是无边框的,带有灰度图像,我想对其着色

在我的NSButton子类中:

- (void)drawRect:(NSRect)dirtyRect{

    if ([self.cell mouseDownFlags] == 0) {

        [[NSColor redColor] set];

    } else {

        [[NSColor blackColor] set];

    }

    NSRectFillUsingOperation(dirtyRect, NSCompositePlusDarker);

    [super drawRect:dirtyRect];
}

尝试使用
setFill

[[NSColor redColor] setFill];