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