NavigationController导航栏中添加多个UIBarButtonItem

来源:未知 责任编辑:智问网络 发表时间:2013-11-08 08:45 点击:

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]; 

 

 

摘自 计算机学习村落

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Lexical or Preprocessor Issue 'xxx.h
    • ios学习笔记(二)xcode 4.3.2下实现基本交互
    • ios版本的helloworld
    • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
    • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
    • IOS类似iphone通讯录TableView的完整demo【附源码】
    • UITableView一些方法
    • [iPhone中级]iPhone团购信息客户端的开发 (二)
    • 如何为Iphone应用创建启动界面
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1