NavigationController导航栏中添加多个UIBarButtonItem
NavigationController导航栏中添加多个UIBarButtonItem
在实际的开发中,导航器是最重要的容器之一,我们经常要在导航栏中添加各种样式的按钮,添加一个按钮很简单,代码如下图:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Setting" style:UITabBarSystemItemContacts
target:self action:@selector(clickSettings:)];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
其中按钮的样式可以有多种,具体的可以参考:https://developer.apple.com/library/ios/prerelease/#documentation/UIKit/Reference/UIBarButtonItem_Class/
在有些项目中要在右面添加两个按钮,实现的样式如下图:
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 45)];
[tools setTintColor:[self.navigationController.navigationBar tintColor]];
[tools setAlpha:[self.navigationController.navigationBar alpha]];
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:@selector(clickSettings:)];
UIBarButtonItem *anotherButton1 = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UITabBarSystemItemContacts
target:self action:@selector(clickEdit:)];
[buttons addObject:anotherButton];
[anotherButton release];
[buttons addObject:anotherButton1];
[anotherButton1 release];
[tools setItems:buttons animated:NO];
[buttons release];
UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithCustomView:tools];
self.navigationItem.rightBarButtonItem = myBtn;
[myBtn release];
[tools release];
摘自 计算机学习村落
相关新闻>>
- iphone关于单倍图和二倍图(导航 背景 变高)
- Iphone用UINavigationController实现在两个页之间导航(上)
- iphone用UINavigationController实现在两个页之间导航(下)
- 在iPhone应用的导航栏添加自定义标题
- iPhone半透明状态栏与导航条错位的解决办法
- iPhone开发 tabBarController与UINavigationController结合
- iPhone开发 tabBarController与UINavigationController结合
- 自定义导航栏按钮
- IOS学习七:UINavigationController控件的初步
- iPhone开发--返回UINavigationController的根视图
- 发表评论
-
- 最新评论 更多>>