标签:
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _toolbar = [[UIToolbar alloc]init]; _toolbar.frame = CGRectMake(0, 0, 320, 45); //以标题命名的按钮 _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
标签:
原文地址:http://www.cnblogs.com/Fredric-2013/p/5208197.html