转自:http://blog.csdn.net/zhuzhihai1988/article/details/7701998

第一种:

UIImage *searchimage=[UIImage imageNamed:@"search.png"];

UIBarButtonItem *barbtn=[[UIBarButtonItem alloc] initWithImage:nil style:UIBarButtonItemStyleDone target:self action:@selector(searchprogram)];

barbtn.image=searchimage;

self.navigationItem.rightBarButtonItem=barbtn;

这种设置出来的外观不好控制

第二种:

UIButton*rightButton = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,30,30)];

[rightButtonsetImage:[UIImageimageNamed:@"search.png"]forState:UIControlStateNormal];

[rightButtonaddTarget:selfaction:@selector(searchprogram)forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem*rightItem = [[UIBarButtonItemalloc]initWithCustomView:rightButton];

[rightButton release];

self.navigationItem.rightBarButtonItem= rightItem;

[rightItem release];

这种图片将填满button,大小可控

第三种:

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(methodtocall:) ];

如何让navigationItem.rightBarButtonItem隐藏消失?

self.navigationItem.rightBarButtonItem=nil;

即可实现

关于NavigationItem.rightBarButtonItem设置的更多相关文章

  1. navigationItem.rightBarButtonItem 设置背景图片,颜色更改解决的方法

    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@& ...

  2. navigationItem的设置和titleView的设置

    设置导航栏中间的标题 self.navigationItem.title = @"title"; 设置导航栏的主题颜色 self.navigationBar.barTintColo ...

  3. iOS 将navigationItem.titleView设置为自定义UISearchBar (Ficow实例讲解)

    这篇文章可以解决以下问题: 1.将searchBar设置为titleView后,无法调整位置的问题 : 2.searchBar的背景色无法设置为透明色的问题: 3.searchBar输入框内用户输入的 ...

  4. IOS navigationItem 设置返回button,title图片和rightBarButtonItem

    1.自己定义返回button UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" st ...

  5. 【iOS开发-22】navigationBar导航条和navigationItem设置:基本搞定导航条上的文字和按钮以及各种跳转

    http://blog.csdn.net/weisubao/article/details/39646739?utm_source=tuicool&utm_medium=referral (1 ...

  6. 设置导航栏 self.navigationItem.titleView 居中

    喜欢交朋友的加:微信号 dwjluck2013-(void)viewDidLayoutSubviews{ [self setDisplayCustomTitleText:@"每日头条&quo ...

  7. navigationItem的leftBarButtonItem和rightBarButtonItem隐藏

    - (void)showEdit { if (不符合显示条件) { self.navigationItem.rightBarButtonItem.customView.hidden = YES; // ...

  8. leftBarbuttonItem/rightBarButtonItem和leftBarbuttonItems/rightBarButtonItems相关问题

    仿写项目的时候,出现了一个Bug:点击右边的"编辑","编辑"变为"完成",左侧出现"全选","删除" ...

  9. IOS 设置导航栏

    //设置导航栏的标题 self.navigationItem setTitle:@"我的标题"; //设置导航条标题属性:字体大小/字体颜色…… /*设置头的属性:setTitle ...

随机推荐

  1. ZH奶酪:纯CSS自定义Html中Checkbox复选框样式

    原文链接:http://www.lrxin.com/archives-683.html 首先看下效果: 点击演示地址查看实例. 首先,需要添加一段CSS隐藏所有的Checkbox复选框,之后我们会改变 ...

  2. The platform of the target `Pods` (iOS 4.3) is not compatible 错误

    一:使用 cocoaPod错误 The platform of the target `Pods` (iOS 4.3) is not compatible with `AFNetworking (1. ...

  3. Oracle-client支持exp|imp|rman

    官方精简版的驱动,不支持持exp/imp/rman,故需要安装oracle_client客户端. 实验环境: Centos6.5 x64   Oracle 11.2.0.4.0 Oracle_clie ...

  4. 在Ubuntu16.04 64bit上安装sublime text 3

    安装sublime text 3 根据官网上提供的安装说明 https://www.sublimetext.com/docs/3/linux_repositories.html  进行安装, 首先是 ...

  5. 基于 Vue BootStrap的迷你Chrome插件

    代码地址如下:http://www.demodashi.com/demo/14306.html 安装 安装 Visual Studio Code 和Chrome, 自行FQ 详细安装这里略过 安装包管 ...

  6. iOS利用SDWebImage实现缓存的计算与清理

    概述 可以仅仅清理图片缓存, 也可以清理所有的缓存文件(包括图片.视频.音频等). 详细 代码下载:http://www.demodashi.com/demo/10717.html 一般我们项目中的缓 ...

  7. Web Service——CXF+Spring 整合

    结合spring框架来实现CXF发布SOAP协议的服务,步骤基本相同,所不同的是的多了一些配置项,步骤如下 1. 服务端 第一步:创建web项目(引入jar包) 第二步:创建SEI接口 import ...

  8. 提高PHP编码的一些技巧

    1.不要使用相对路径 例如 require_once('../../lib/some_class.php'); 该方法有很多缺点: 1)它首先查找指定的php包含路径, 然后查找当前目录 2)如果该脚 ...

  9. JDK 生成数字证书

    JDK(keytool.exe)生成数字证书 2010-11-21 15:52 QUOTE: keytool JAVA是个密钥和证书管理工具.它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数 ...

  10. 更新开源库到pods上时报CocoaPods was not able to update the `master` repo的解决办法

    今天在更新我的开源库到pods上时,使用以下命令时,报错了... pod trunk push SwiftPopMenu.podspec 错误内容: CocoaPods was not able to ...