@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_toolbar = [[UIToolbar alloc]init];
_toolbar.frame = CGRectMake(, , , );
//以标题命名的按钮
_barItem = [[UIBarButtonItem alloc]
initWithTitle:@"Item1" style:UIBarButtonItemStyleDone target:self action:@selector(doClick)];
//以图片作为背景的按钮
UIImage *_image = [UIImage imageNamed:@"fresh.png"];
_barItem1 = [[UIBarButtonItem alloc]
initWithImage:_image style:UIBarButtonItemStylePlain target:self action:@selector(doClick)];
NSMutableArray *array = [NSMutableArray array];
[array addObject:_barItem];
[array addObject:_barItem1];
//在工具栏中添加按钮
[_toolbar setItems:array animated:YES];
[self.view addSubview:_toolbar];
}
-(void)doClick{
NSLog(@"doClick");
}
@end