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就是使用链式编程写的第三方框架. 二.写法 链式编程写法不同于传统方式, ...
随机推荐
- LinQ to SQL 查询
LINQ to SQL 是将对象关系映射到.NET框架中的一种实现.它可以将关系数据库映射为.NET Framework中的一些类. 然后,开发人员就可以通过使用 LINQ to SQL对数据库中的数 ...
- ubuntu 14.04 下 yii2 下载安装
先安装composer ,安装了curl的情况下: curl -s http://getcomposer.org/installer | php mv composer.phar /usr/local ...
- Oracle字符集查看
Oracle字符集是一个字节数据的解释的符号集合,有大小之分,有相互的包容关系.ORACLE 支持国家语言的体系结构允许你使用本地化语言来存储,处理,检索数据.它使数据库工具,错误消息,排序次序,日期 ...
- EffectiveC#01--避免返回内部类对象的引用
此篇是对00中第3点的再一次阐述. 1.如果一个属性返回一个引用类型,那么调用者就可以访问这个对象的公共成员,也包括修改这些属性的状态. public class MyBusinessObject { ...
- Volley的三种基本用法StringRequest的Get和post用法以及JsonObjectRequest
首先做出整个应用的全局请求队列 package com.qg.lizhanqi.myvolleydemo; import android.app.Application; import com.and ...
- CDMA电信短信猫支持189等电信号码可二次开发
CDMA电信短信猫支持189等电信号码可二次开发 这款短信猫采用法国wavecom Q2358C模块,支持短信猫二次开发,可提供短信猫二次开发包下载测试.提供相关资料文档. 此款CDMA电信短信猫有串 ...
- 返回某个界面——nav
NSInteger index=[[self.navigationController viewControllers]indexOfObject:self]; [self.navigationC ...
- 从C到C++的升级
C++的语言类型 C++是静态的强类型语言. 静态语言:数据类型在编译期间检查,因此在写程序时需要声明变量的类型 强类型语言:强调数据类型,不同的数据类型间的转换需要进行强制类型转换 C与C++的关系 ...
- R语言学习笔记(数据预处理)
setwd("d:/r/r-data/")data=read.table("salary.txt",header=T)attach(data)mean(Sala ...
- maven使用笔记一 下载json-lib引发的问题
一.问题描述(IDEA中): 1,在pom.xml中配置了 <dependency> <groupId>net.sf.json-lib</groupId> < ...