2013-10-24 30 views
2

我想使NSButton作爲'默認'按鈕,以便當我點擊「Enter」鍵點擊按鈕(即它的Click Action被調用)時,我是可以通過設置其鍵等於'\ r'或在Xib中按'Enter'鍵來完成。如何使NSButton作爲默認沒有標題欄到其窗口

但如果相同的窗口沒有標題欄,則默認按鈕不起作用。

我已讓mywindow的無邊距programitcally

[mywindow setStyleMask:NSBorderlessWindowMask]; 

仍然沒有幫助嘗試。

所以我的問題是如何使NSButton作爲'默認'按鈕沒有標題欄到其窗口。

謝謝。

回答

0

試試下面的程序: -

NSRect myRect = NSMakeRect(0.0, 0.0, 1, 1); 
NSButton *defaultButton = [[NSButton alloc] initWithFrame:myRect]; 

[defaultButton setKeyEquivalent:@"\r"]; 
[defaultButton setTarget:self]; 
[defaultButton setAction:@selector(yourActionMethod:)]; 
[[self view] addSubview:defaultButton]; 
[defaultButton release]; 
0

documentation

使用,除非實現canBecomeKeyWindow或canBecomeMainWindow到 回報是

NSBorderlessWindowMask不能成爲關鍵,主, 窗口

子類NSWindow和執行canBecomeKeyWindowcanBecomeMainWindowNSButton設置爲不帶標題欄窗口的「默認」按鈕。

@interface PBWindow : NSWindow 

@end 
@implementation PBWindow 

-(BOOL)canBecomeKeyWindow 
{ 
    return YES; 
} 
@end 

集NSWindow類名PBWindow:

enter image description here

輸出:

enter image description here

相關問題