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就是使用链式编程写的第三方框架. 二.写法 链式编程写法不同于传统方式, ...
随机推荐
- 原生AJAX如何异步提交数据?
AJAX概述 AJAX:Asynchronous Javascript And XML,异步的JS和XML.2001,Google为了改进搜索的用户体验,提出了GoogleSugguest效果,正式提 ...
- linux在文件打包和压缩
1. 打包和压缩文件 linux现在经常使用gzip和bzip2要压缩的文件.tar压缩文件. 经常使用的扩展: *.gz gzip压缩文件 *.bz2 bzip2压缩的文件 *.tar t ...
- ThinkPHP视图查询详解
ThinkPHP视图查询详解 参考http://www.jb51.net/article/51674.htm 这篇文章主要介绍了ThinkPHP视图查询,需要的朋友可以参考下 ThinkP ...
- Android ---------- 清单文件中Activity常规设置
<activity android:name="xxxxx" android:alwaysRetainTaskState="true" android:c ...
- [hdu5136]Yue Fei's Battle 2014 亚洲区域赛广州赛区J题(dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 现场赛的时候由于有个地方有点小问题,没有成功AC,导致与金牌失之交臂. 由于今天下 ...
- (原+转)使用opencv的DFT计算卷积
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5462665.html 参考网址: http://blog.csdn.net/lichengyu/art ...
- 用CSS截断字符串
方法一: <div style="width:300px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;&q ...
- CI框架微信开发-自定义菜单
在CI框架下面实现了自定义菜单功能.写了一个model,一个类库.顺便附带access_token的实现方式 <?php class Makemenu{ public $menustr; pub ...
- DOM和jQuery
一.DOM 在学习DOM之前你应该已经具备了以下三个知识点的应用:HTML CSS javascript DOM 是 W3C(万维网联盟)的标准. W3C DOM 标准被分为 3 个不同的部分: 核心 ...
- Python中for\while的用法
代码示例 board = [] for i in range(5): board.append(i) print board board = [] i = 0 while i < 5: boar ...