- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试以编程方式向 View 添加一个按钮,我希望它在单击时保持“插入”状态,直到再次单击它。从我读过的内容来看,用于此目的的按钮似乎是 NSPushOnPushOffButton
。这是 Apple 对其的描述:
The first click both highlights and causes the button to be “pushed in” if the button is bordered; a second click returns it to its normal state. This option is called “Push On Push Off” in Interface Builder’s Button Inspector.
它在我的程序中不起作用,所以我创建了一个 SSCCE,我将在下面包含它。我的问题是单击时按钮没有停留,而是像普通按钮一样弹出。我不确定我是否遗漏了有关此按钮应该如何执行的某些信息,或者我是否只是错误地实现了它(这是我第一次尝试以编程方式执行 UI),但其他按钮类型如因为 NSToggleButton
工作,所以除非 NSPushOnPushOffButton
有什么特别之处,否则我看不出哪里出错了。如果有人可以提出更好的解决方案或解释我哪里出错了,那就太好了。谢谢!
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSRect buttonFrame = NSMakeRect(0,0,200,200);
NSButton *button = [[NSButton alloc]initWithFrame:buttonFrame];
[self.window.contentView addSubview:button];
[button setButtonType:NSPushOnPushOffButton];
}
@end
最佳答案
看来你必须设置一个“bezel style”,例如
[button setBezelStyle:NSRegularSquareBezelStyle];
将其添加到您的示例代码后,它按预期工作。
关于objective-c - NSPushOnPushOffButton 不停留 "Pushed In",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17506712/
我正在尝试以编程方式向 View 添加一个按钮,我希望它在单击时保持“插入”状态,直到再次单击它。从我读过的内容来看,用于此目的的按钮似乎是 NSPushOnPushOffButton。这是 Appl
我是一名优秀的程序员,十分优秀!