在导航栏中添加多个按钮 [英] Add multiple Buttons in Navigation Bar

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

问题描述

任何人都可以帮我添加多个自定义按钮到导航栏的右侧栏。
如果可能的话,请回答详细的代码,以便我能正确理解。

Can any one help me to add more than one custom button to the right bar of the navigation bar. If possible please answer with the detail code, so that i can understand it properly.

推荐答案

//添加一个右边btn到导航栏

//add a right btn to the navigation bar

UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 75.0f, 30.0f)];

UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setFrame:CGRectMake(0.0f, 0.0f, 30.0f, 30.0f)];
[btn1 setTitle:@"1" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btn1Tap:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:btn1];

UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn2 setFrame:CGRectMake(35.0f, 0.0f, 30.0f, 30.0f)];
[btn2 setTitle:@"2" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(btn2Tap:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:btn2];

UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:customView];
[self.navigationItem setRightBarButtonItem:rightBtn];

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

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