gpt4 book ai didi

objective-c - NSPushOnPushOffButton 不停留 "Pushed In"

转载 作者:搜寻专家 更新时间:2023-10-30 20:19:17 26 4
gpt4 key购买 nike

我正在尝试以编程方式向 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com