IOS Custom NavigationItem --写titleView
//先自己写一个titleView
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];//allocate titleView
titleView.backgroundColor=[UIColor blackColor];
//Create UILable
UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(100, 0, 50, 20)];//allocate titleText
titleText.backgroundColor = [UIColor clearColor];
[titleText setText:@"Title"];
[titleView addSubview:titleText];
[titleText release];//release titleText //Create Round UIButton
UIButton *btnNormal = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnNormal setFrame:CGRectMake(0, 0, 40, 20)];
[btnNormal addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[btnNormal setTitle:@"Normal" forState:UIControlStateNormal];
[btnNormal setFont:[UIFont systemFontOfSize:8]];
[titleView addSubview:btnNormal]; //Set to titleView
self.navigationItem.titleView = titleView;
[titleView release];//release titleView //Custom backgroundImage UIButton
UIButton *btnCustom = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnCustom setFrame:CGRectMake(0, 0, 32, 32)];
[btnCustom addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[btnCustom setTitle:@"CB" forState:UIControlStateNormal];
[btnCustom setBackgroundImage:[UIImage imageNamed:@"whiteButton.png"] forState:UIControlStateNormal];
[btnCustom setBackgroundImage:[UIImage imageNamed:@"blueButton.png"] forState:UIControlStateHighlighted];
//Create UIBarButtonItem with the customed button
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:btnCustom];//allocate rightBarButton
//Set to rightBarButtonItem
self.navigationItem.rightBarButtonItem = rightBarButton;
[rightBarButton release];//release rightBarButton
IOS Custom NavigationItem --写titleView的更多相关文章
- iOS中navigationItem的titleView如何居中
开发过程中,发现titleview很难居中,通过各种尝试终于找到了解决方法. 首先清楚你个概念: leftBarButtonItem,导航条中左侧button. rightBarButtonItem, ...
- 如何:为iOS 的方法写注释 让xcode 能够索引得到?
如何:为iOS 的方法写注释 让xcode 能够索引得到? 按照如下方法为ios项目写注释: 将会让xcode能够索引得到如下结果:
- 谈谈iOS开发如何写个人中心这类页面--静态tableView页面的编写
本文来自 网易云社区 . 一.本文讲的是什么问题? 在开发 iOS 应用时,基本都会遇到个人中心.设置.详情信息等页面,这里截取了某应用的详情编辑页面和个人中心页面,如下: 我们以页面结构的角度考虑这 ...
- iOS 将navigationItem.titleView设置为自定义UISearchBar (Ficow实例讲解)
这篇文章可以解决以下问题: 1.将searchBar设置为titleView后,无法调整位置的问题 : 2.searchBar的背景色无法设置为透明色的问题: 3.searchBar输入框内用户输入的 ...
- iOS之在写一个iOS应用之前必须做的7件事(附相关资源)
本文由CocoaChina--不再犹豫(tao200610704@126.com)翻译 作者:@NIkant Vohra 原文:7 Things you must absolutely do befo ...
- iOS使用宏写单例
本文只介绍ARC情况下的单例 过去一直背不下来单例如何写,就是知道这么回事,也知道通过宏来写单例,但是一直记不住,今天就来记录一下 - (void)viewDidLoad { [super v ...
- iOS:Block写递归
首先来一个 oc 的递归: - (int)sum:(int)num { ) { return num; } ]; } 写递归算法只需要记住两点即可: 1. 有一个明确的出口 2. 不满足条件出口时,自 ...
- IOS隐藏navigationItem左右按钮的方法
在移除一个View的时候或者根据需要希望让navigationItem的rightBarButtonItem或者leftBarButtonItem处于隐藏状态,一个简单的方法如下: self.na ...
- iOS:用Block写一个链式编程
一.介绍 链式编程是一个比较新颖的编程方式,简单直观,用起来也比较舒服.目前比较有名的Mansory和BabyBlueTooth就是使用链式编程写的第三方框架. 二.写法 链式编程写法不同于传统方式, ...
随机推荐
- Thinkphp多表联查mysql写法
$model=M("user","","mysql://root:222222@localhost:3306/jiaoyou"); //换数 ...
- iOS 3DES加密 和 java 3DES 解密
首先进入头文件: #import <CommonCrypto/CommonDigest.h> #import <CommonCrypto/CommonCryptor.h> #i ...
- Tcp实现简单的大小写转换功能
有这样一个需求: 客户端给读物段发送文本,服务端会将文本转换为大写再返回客户端 而且客户端可以不断的进行文本转换,当客户端输入over时,转换结束. 分析: 既然是操作设备上的数据,那么久可以使用io ...
- 虚拟机IOS开发环境搭建教程
来源:http://www.cnblogs.com/xiaoyaoju/archive/2013/05/21/3091171.html 安装条件: 硬件:一台拥有支持虚拟技术的64位双核处理器和2GB ...
- Coreseek:常见的问题2
1.failed to lock XXXXX.spl档 这是当你构建的指数将是一个问题,您不必打开searchd服务关闭,既然你开searchd维修,他将建立呼叫xxx.spl临时文件,施工时的指数会 ...
- Qt之操作Excel
Visual Basic for Applications(VBA)是一种Visual Basic的一种宏语言,主要能用来扩展Windows的应用程式功能,特别是Microsoft Office软件. ...
- Git 推送分支
1.推送本地分支到远程: git push origin master 推送本地分支 master 到 远程的 origin 上面 git push origin test 将本地分支test推 ...
- 从 mysql 客户端导出数据库 mysqldump
window+r 打开cmd 输入 mysqldump -u mysql用户名 -p 数据库名 > 要导出的位置 (注意,最后没有分号) 然后输入密码即可 ^_^
- Http请求和响应报文基础知识
一 HTTP请求报文(http://en.wikipedia.org/wiki/List_of_HTTP_header_fields) 请求报文由三部分组成:请求行,请求头和请求体. 请求行:请求方法 ...
- Struts2 标签库详解2
Struts2标签库 包括: OGNL Struts2标签分类 控制标签 :(if, elseif,else, iterator, append, merge, generator, subset, ...