UINavigationItem:再添加一个按钮 [英] UINavigationItem: Add one more button

查看:45
本文介绍了UINavigationItem:再添加一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在NavigationItem中添加新按钮?假设我需要将其添加到右键附近.

How can I add new button in navigationItem? Say I need to add it near right button.

左右代码.

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_cancelButton];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_shareButton];

如何添加一个按钮?

推荐答案

在Navigationcontroller的右侧有多种添加一个按钮的方法.下面给出了一种Simplist方式

There are Different Approach to add more then one Buttons on right side of navigationcontroller.one of the Simplist way is given below

 UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];

UIButton *exampleButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
exampleButton1.frame = CGRectMake(0, 2, 30, 40);
[exampleButton1 addTarget:self action:@selector(FirstMethod) forControlEvents:UIControlEventTouchUpInside];
[exampleButton1 setImage:[UIImage imageNamed:@"image1.png"] forState:UIControlStateNormal];
[buttonView addSubview:exampleButton1];


UIButton *exampleButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
exampleButton2.frame = CGRectMake(70, 2, 30, 40);
[exampleButton2 addTarget:self action:@selector(Second method) forControlEvents:UIControlEventTouchUpInside];
[exampleButton2 setImage:[UIImage imageNamed:@"image2.png"] forState:UIControlStateNormal];

[buttonView addSubview:exampleButton2];

 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonView];

希望对您有帮助.谢谢

这篇关于UINavigationItem:再添加一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆