在使用自定义图像和备用图像创建 Cocoa 斜角按钮时,我遇到了一种奇怪的行为。在按下状态下,按钮背景变为白色。我将按钮添加为透明窗口(HUD 窗口)的子视图。
我正在尝试我所知道的每一种技术:
NSButton *closeButton = [[NSButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 30.0, 30.0)];
[closeButton setFrameOrigin:NSMakePoint(0.0, 0.0)];
[closeButton setImagePosition:NSImageOnly];
[closeButton setAction:@selector(closeWindowAction:)];
[closeButton setBordered:NO];
[closeButton setTransparent:NO];
[closeButton setImage:[NSImage imageNamed:@"icon-tclose-off"]];
[closeButton setAlternateImage:[NSImage imageNamed:@"icon-tclose-on"]];
[closeButton setBezelStyle:NSShadowlessSquareBezelStyle];
[closeButton setButtonType:NSMomentaryLightButton];
//[[closeButton cell] setBackgroundColor:[NSColor clearColor]];
[[closeButton cell] setHighlightsBy:NSChangeBackgroundCellMask|NSCellLightsByContents];
//[[closeButton cell] setHighlightsBy:NSContentsCellMask];
//[[closeButton cell] setShowsStateBy:0|NSContentsCellMask];
我也试过
[closeButton setButtonType:NSMomentaryChangeButton];
[[closeButton cell] setHighlightsBy:NSContentsCellMask];
没有结果。
您可以在随附的屏幕截图中看到错误行为:
覆盖 HUD 窗口的斜角按钮:
错误的斜角按钮背景: