2 bluetooth99 bluetooth99 于 2013.05.09 10:07 提问

UINavigationItem:添加按钮

CSDN移动问答

如何在navigationItem中添加新按钮?需要在右侧按钮附近:

左右按钮:

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

再添加一个?

2个回答

redCoral_
redCoral_   2013.05.09 13:35
已采纳

有很多方法可以实现在右侧添加一个按钮,我认为最简单的方法:

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];
zhanglei5415
zhanglei5415   Rxr 2013.05.09 10:21

放中间的话可以用

self.navigationItem.titleView=.....
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!