MacOS 开发

来源:互联网 发布:linux时间同步 编辑:程序博客网 时间:2024/06/01 07:58

NSBezelStyle

typedef NS_ENUM(NSUInteger, NSBezelStyle) {    NSBezelStyleRounded           = 1,    NSBezelStyleRegularSquare     = 2,    NSBezelStyleDisclosure        = 5,    NSBezelStyleShadowlessSquare  = 6,    NSBezelStyleCircular          = 7,    NSBezelStyleTexturedSquare    = 8,    NSBezelStyleHelpButton        = 9,    NSBezelStyleSmallSquare       = 10,    NSBezelStyleTexturedRounded   = 11,    NSBezelStyleRoundRect         = 12,    NSBezelStyleRecessed          = 13,    NSBezelStyleRoundedDisclosure = 14,    NSBezelStyleInline NS_ENUM_AVAILABLE_MAC(10_7) = 15,};

显示效果

1-14 等数字代表 NSBezelStyle 的枚举

  • 枚举中没有3、4,如果设置样式为3、4,则会沿用2的风格。
  • 样式为 1、2、6、8、10 的时候,尺寸才会修改。 Square 结尾的样式都可以有效的修改尺寸。所以当你修改尺寸失败时,别忘记查看下自己的 bezelStyle。

无文字

有文字


测试代码

- (void)addSerialBtn{    CGFloat btnW = 80;    CGFloat btnH = 40;    for (int i = 0; i < 14; i++) {        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect( 20 + (i % 5) * (btnW + 5) ,50 + (i / 5) * (btnH + 40), btnW, btnH)];        btn.wantsLayer = YES;        btn.bezelStyle = i;        NSString *btnName = [NSString stringWithFormat:@"按钮 - %d",i];        [btn setTitle:@"按钮"];        btn.layer.backgroundColor = [NSColor cyanColor].CGColor;        [self.window.contentView addSubview:btn];        NSTextField *field = [[NSTextField alloc]initWithFrame:NSMakeRect(CGRectGetMinX(btn.frame), CGRectGetMinY(btn.frame) - 22, btnW, 20)];        field.stringValue = btnName;        [self.window.contentView addSubview:field];    }}
原创粉丝点击