NSPopUpButton

作者: 提笔挥墨 | 来源:发表于2016-07-28 16:13 被阅读946次

NSPopUpButton 下拉列表按钮,有两种。一种只有下拉箭头的按钮,另一种是既有上拉,也有下拉。

  • 如果设置只有向下的箭头,这最上面的item 只会出现一次,一旦其他的item选中之后, 就找不到第一个item了。 所以, 一般初始的item是一个不用的提示,比如要选择地区,那么第一个就放城市的提示信息,就行了。
  • 如果既有上拉按钮也有下拉按钮,那么所有的item都会显示在下拉列表框中。

## ****下面以只有下拉箭头的按钮为例进行说明:

    // pullsDown 设置为 YES 只有向下的箭头
    NSPopUpButton *popBtn = [[NSPopUpButton alloc] initWithFrame:CGRectMake(0, 100, 100, 30) pullsDown:YES];
    [popBtn addItemWithTitle:@"城市"];
    [popBtn addItemWithTitle:@"上海"];
    [popBtn addItemWithTitle:@"广州"];
    [popBtn addItemWithTitle:@"深圳"];
    [popBtn addItemWithTitle:@"河南"];
    
    [self.view addSubview:popBtn];
    
    // popBtn 的点击事件
    [popBtn setTarget:self];
    [popBtn setAction:@selector(handlePopBtn:)];

NSPopUpButton 选中item的相应事件:

- (void)handlePopBtn:(NSPopUpButton *)popBtn {
    // 选中item 的索引
    NSLog(@"%d", popBtn.indexOfSelectedItem);
//    [popBtn selectItemAtIndex:popBtn.indexOfSelectedItem];
    popBtn.title = popBtn.selectedItem.title;
}

只有下拉按钮.jgp 上拉和下拉按钮都有的效果图

相关文章

  • NSPopUpButton

    NSPopUpButton 下拉列表按钮,有两种。一种只有下拉箭头的按钮,另一种是既有上拉,也有下拉。 如果设置只...

  • Macosx NSPopUpButton

    和NSComBox相比nspopupbutton还是比较简单的,只需要设置titles即可 - (void)vie...

  • NSPopupButton with same title

    通过 addItemWithTitle,addItemsWithTitles 不可以添加相同title的item。...

  • Mac OS的选项-NSPopUpButton(多选一)/NSM

    Mac OS上,坐标系统原点位于左下角! 下面使用的素材图片: Mac端除了NSButton按钮作为选项外,还可以...

网友评论

  • 晓龙歌:你好 请问如果同时有很多个这种选择框 会出现遮挡的情况吗?
    晓龙歌:哦哦 macOS下的方法自带方法哟。。。那应该不会出现遮挡的情况

本文标题:NSPopUpButton

本文链接:https://www.haomeiwen.com/subject/xrmajttx.html