NSComboBox

作者: L柠_檬 | 来源:发表于2016-09-01 13:21 被阅读199次
    NSView *viewExt = [[NSView alloc] initWithFrame:NSMakeRect(100, 100, 180, 40)];
    
    self.Ext = [[NSComboBox alloc] 
    initWithFrame:NSMakeRect(80, 8, 100, 25)];
    [self.Ext addItemsWithObjectValues:@[@".bmp", @".jpg", 
    @".png", @".tif"]];
    //默认选择第几个
    [self.Ext selectItemAtIndex:0];
    [viewExt addSubview:  self.Ext];
    [self.view addSubview:viewExt];
    

    //self.Ext.stringValue 即选中后的值
    NSLog(@"%@", self.Ext.stringValue);


    NSButton *button = [[NSButton alloc]init];
    button.frame = CGRectMake(300, 100, 100, 30);
    [button setTitle:@"打印"];
    [button setTarget:self];    
    [button setAction:@selector(buttonClick:)];
    
    [self.view addSubview:button];

//打印self.Ext.stringValue
- (void)buttonClick:(NSButton *)button{
    
     NSLog(@"%@", self.Ext.stringValue);
    
}

屏幕快照 2016-09-01 下午1.23.22.png

相关文章

网友评论

    本文标题:NSComboBox

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