NSButton 详解

## NSButton ****初始化,常用属性的设置

    NSButton *btn = [[NSButton alloc] initWithFrame:CGRectMake(100, 0, 100, 100)];
    /**
     *     
     * 这4中风格基本一样, 点击带蓝色的是1,点击带灰色的是2、3、4
     NSRoundedBezelStyle          = 1,
     NSRegularSquareBezelStyle    = 2,
     NSThickSquareBezelStyle      = 3,
     NSThickerSquareBezelStyle    = 4,
     */
    [btn setBezelStyle:NSThickSquareBezelStyle];

  
    [btn setTitle:@"点击"];
    /**
     *  btn的类型,像, radio, check, 开关按钮都用这个属性设置
     */
    [btn setButtonType:NSMomentaryLightButton];
    
    // 设置按钮上文字的对齐方式
    //    [[btn cell] setAlignment:NSTextAlignmentCenter];
    //    [[btn cell] setFont:[NSFont systemFontOfSize:30]];
    // 一般用法, 用这个就够了, 设置btn的属性,别用cell,坑人
    
    [btn setAlignment:NSTextAlignmentCenter];
    [btn setFont:[NSFont systemFontOfSize:30]];
    [btn setSound:[NSSound soundNamed:@"Pop"]];
    [self.view addSubview:btn];
    [btn setTarget:self];
    [btn setAction:@selector(handelClick)];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容