MacOS 开发

来源:互联网 发布:php在线答题系统 编辑:程序博客网 时间:2024/06/05 15:07
  • NSButtonTypeSwitch 就是勾选样式
    其他样式可参考:http://blog.csdn.net/lovechris00/article/details/77976480
  • allowsMixedState 代表是否可以混合选择。YES-有三种状态,-1、1、0;NO-2种状态,1、0。
  • 使用 setAction 来监听。
  • 只设置 buttonType 即可,不用设置 bezielType,设置了也无效。存疑: 这两者如何组合使用?
- (void)addCheckBtn{    NSButton *btn0 = [[NSButton alloc]init];    btn0.frame = NSMakeRect(100, 100, 100, 100);    btn0.wantsLayer = YES;    btn0.layer.backgroundColor = [NSColor cyanColor].CGColor;    [btn0 setButtonType:NSButtonTypeSwitch];    //YES-有三种状态,-1、1、0    //NO-2种状态,1、0    btn0.allowsMixedState = YES;    [self.window.contentView addSubview:btn0];    [btn0 setAction:@selector(valueChange:)];}- (void)valueChange:(NSButton *)sender{    NSButton *checkBtn = sender;    BOOL isOn = checkBtn.state;    NSLog(@" %d",isOn);}