lor*_*isi 8 cocoa nsbutton nsbuttoncell
当使用自定义图像和替代图像创建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];
Run Code Online (Sandbox Code Playgroud)
我也试过了
[closeButton setButtonType:NSMomentaryChangeButton];
[[closeButton cell] setHighlightsBy:NSContentsCellMask];
Run Code Online (Sandbox Code Playgroud)
没有结果.
您可以在附加的屏幕截图中看到错误的行为:
斜角按钮覆盖HUD窗口:

错误的斜角按钮背景:

创建按钮
NSButton *myButton;
myButton = [[NSButton new] autorelease];
[myButton setTitle: @"Hello!"];
[myButton sizeToFit];
[myButton setTarget: self];
[myButton setAction: @selector (function:)];
Run Code Online (Sandbox Code Playgroud)
将按钮添加到窗口
unsigned int styleMask = NSTitledWindowMask
| NSMiniaturizableWindowMask;
NSWindow *myWindow;
myWindow = [NSWindow alloc];
/*get the size of the button*/
NSSize buttonSize;
buttonSize = [myButton frame].size;
/*set window content rect with the size of the button, and with an origin of our choice; (100, 100)*/
NSRect rect;
rect = NSMakeRect (100, 100,
buttonSize.width,
buttonSize.height);
myWindow = [myWindow initWithContentRect: rect
styleMask: styleMask
backing: NSBackingStoreBuffered
defer: NO];
[myWindow setTitle: @"my window"];
/*replacing the default window content view with our button*/
[myWindow setContentView: myButton];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6584 次 |
| 最近记录: |