NavigationItem.rightBarButtonItems

前几天遇到需要在导航栏右边添加多个按钮的情况。刚开始不知道如何解决,布局始终不能达到想要的效果,也没注意到 UIBarButtonItem.

后来上网找到了两篇文章,对此做了介绍,在这里做个小结。代码如下:

//二维码扫描
UIBarButtonItem *btn0 = [[UIBarButtonItem alloc] initWithTitle:@""
                                                         style:UIBarButtonItemStyleDone
                                                        target:self
                                                        action:@selector(scan:)];
btn0.image = [UIImage imageNamed:@"scan"];

//注册按钮
UIBarButtonItem *btn1 = [[UIBarButtonItem alloc] initWithTitle:@"注册"
                                                        style:UIBarButtonItemStylePlain
                                                       target:self
                                                       action:@selector(skip)];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:btn0, btn1, nil];

//PS: 先添加到数组的会在右边显示。

参考链接:

  1. 关于NavigationItem.rightBarButtonItem设置
  1. UIBarButtonItem-添加自定义Left或者Right按钮

你可能感兴趣的:(NavigationItem.rightBarButtonItems)