跳过普通的设置左右按钮我们直接讲解给导航栏设置多个按钮 实现代码如下
<span style="font-size:18px;">UIToolbar *tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 45)];</span>
<span style="font-size:18px;">
[tools setTintColor:[self.navigationController.navigationBar tintColor]];</span>
<span style="font-size:18px;">
[tools setAlpha:[self.navigationController.navigationBar alpha]];</span>
<span style="font-size:18px;">
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
</span>
<span style="font-size:18px;">
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(clickSettings:)];</span>
<span style="font-size:18px;">
UIBarButtonItem *anotherButton1 = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:(UIBarButtonItemStylePlain) target:self action:@selector(clickEdit:)];</span>
<span style="font-size:18px;">
anotherButton1.tintColor = [UIColor redColor];
[buttons addObject:anotherButton];</span>
<span style="font-size:18px;">
[buttons addObject:anotherButton1];
[tools setItems:buttons animated:NO];
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithCustomView:tools];
self.navigationItem.rightBarButtonItem = myButton;
</span>
<span style="font-size:18px;">- (void)clickSettings:(UIBarButtonItem *)clickSettings
{
NSLog(@"我是添加按钮");
}</span>
<span style="font-size:18px;">- (void)clickEdit:(UIBarButtonItem *)clickEdit
{
NSLog(@"我是编辑按钮");
}
</span>