iOS导航栏主题
主要是取得导航栏的appearance对象,操作它就设置导航栏的主题
UINavigationBar *navBar = [UINavigationBar appearance];
常用主题设置
导航栏背景
- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics;
标题
@property(nonatomic,copy) NSDictionary *titleTextAttributes;
// 字典中能用到的key在UIStringDrawing.h中
// 最新版本的key在UIKit框架的NSAttributedString.h中
iOS7返回按钮的箭头样式
@property(nonatomic,retain) UIColor *tintColor;
导航栏的左上角和右上角都是UIBarButtonItem对象,为了统一样式,也可以设置的UIBarButtonItem主题
UIBarButtonItem *item = [UIBarButtonItem appearance];
设置主题的方法
背景
- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics;
文字
- (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state;
导航栏返回按钮背景
- (void)setBackButtonBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics;
iOS6导航栏背景的出图规格
非retina:320x44 px
retina:640x88 px
iOS7导航栏背景的出图规格
retina:640x128 px
自定义导航控制器
自定义导航控制器的步骤:新建一个类,继承自UINavigationController
自定义导航控制器的价值
重写push方法就可以拦截所有压入栈中的子控制器,统一做一些处理
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
重写pop方法就可以拦截所有子控制器的出栈
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
为了在push控制器时隐藏UITabBar,需要做以下设置
viewController.hidesBottomBarWhenPushed = YES;
initailize、load方法的区别
initailize、load都是类方法
当一个类被装载进内存时,就会调用一次load方法(当时这个类还不可用)
当第一次使用这个类时,就会调用一次initailize方法
程序启动完毕后再显示回状态栏(前提是状态栏交给了UIApplication管理)
application.statusBarHidden = NO;
UIImaegView的图片拉伸可以通过storyboard或者xib设置
UIButton不能通过storyboard或者xib设置,必须通过代码
swift中设置导航栏主题的做法:
func setupnav(){
let navbar = UINavigationBar.appearance() // 获取导航栏的appearance对象
navbar.barTintColor = barTintColor
let navbartitleDict:NSDictionary = [NSForegroundColorAttributeName:navtextcolor,NSFontAttributeName: UIFont.systemFontOfSize(18)]
navbar.titleTextAttributes = navbartitleDict as? [String : AnyObject];
navbar.tintColor = navtextcolor
navbar.setBackgroundImage(UIImage(named: "daohang"), forBarMetrics: UIBarMetrics.Default)
//去除返回按钮文本
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: UIBarMetrics.Default)
let leftDict:NSDictionary = [NSForegroundColorAttributeName:navtextcolor,NSFontAttributeName: UIFont.systemFontOfSize(15)]
UIBarButtonItem.appearance().setTitleTextAttributes(leftDict as? [String : AnyObject], forState: UIControlState.Normal)
}
导航栏标题不居中问题:
导航栏标题之所以不居中是因为返回的标题太长造成的,只需要把返回按钮的标题修改一下即可
self.navigationController?.navigationBar.topItem?.title = "";
但是要注意上一级页面需要在viewWillAppear中重新设置一下导航栏的标题
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationItem.title = ""
}
iOS导航栏主题的更多相关文章
- IOS开发中设置导航栏主题
/** * 系统在第一次使用这个类的时候调用(1个类只会调用一次) */ + (void)initialize { // 设置导航栏主题 UINavigationBar *navBar = [UINa ...
- [iOS微博项目 - 1.1] - 设置导航栏主题(统一样式)
A.导航栏两侧文字按钮 1.需求: 所有导航栏两侧的文字式按钮统一样式 普通样式:橙色 高亮样式:红色 不可用样式:亮灰 阴影:不使用 字体大小:15 github: https://github ...
- IOS 导航栏属性设置
IOS 7 以上系统导航栏: [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // 返回按钮颜色 [UINaviga ...
- 【Swift】iOS导航栏错乱的原因
#iOS开发高级技巧#导航栏错乱,也就是导航栏的显示效果与内容区不匹配,引发原因很多,其中最重要的有两个原因: 1.在viewwillappear,viewwilldisappear两个函数中,设置导 ...
- 转:ios导航栏设置
原帖:http://www.cocoachina.com/industry/20131104/7287.html 本文提供的代码需要用Xcode 5来执行.如果你还在使用老版本的Xcode,那么在运行 ...
- iOS导航栏背景,标题和返回按钮文字颜色
在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...
- iOS 导航栏黑线,UIImage 枚举处理方式
ios 找出导航栏下面的黑线(可隐藏,改变样式等) http://www.jianshu.com/p/effa4a48f1e3 设置UIImage的渲染模式:UIImage.renderi ...
- ios 导航栏的显示和隐藏切换
从简单的一个没有导航栏的界面A push到另一个有导航栏的界面 B,在界面A的逻辑中加入下面逻辑: 屏幕快照 2016-03-30 上午10.35.24.png 这样完美的处理了这个场景变换需求.引起 ...
- iOS导航栏的正确隐藏方式【转】
简介:在项目中经常碰到首页顶部是无限轮播,需要靠最上面显示.有的设置导航栏为透明等一系列的方法,这个可以借助第三方.或者干脆简单粗暴的直接隐藏掉导航栏.可是push到下一个页面的时候是需要导航栏的,如 ...
随机推荐
- MVC网站后台分离
1.新建一个项目TestAdmin项目类型随便选一个,待会删掉,因为这里我只需要解决方案名称 [项目存放于F盘 F:\TestAdmin] 2.新建一个 ZGJ.Web 的前台MVC项目,将开 ...
- 查看JS object 结构
function lookProperty(obj){ var ob=eval(obj); var property=""; for(var p in ob){ property+ ...
- <poj - 3268> Silver Cow Party 牛のpart 最短路径问题
本题链接 : http://poj.org/problem?id=3268 题目大意:牛们要去聚会,输入N = 顶点数(牛场):M = 边(路)的数目: X = 终点 (聚会点).问题:求来回时间的最 ...
- ECOS-Ecstore证书生产失效问题排查
无法生成证书问题排查 无法生成证书问题排查 author :James,jimingsong@vip.qq.com since :2015-03-02 名称解释(官方) 常见错误 1. 名称解释(官方 ...
- ubuntu enable all Ubuntu software (main universe restricted multiverse) repositories use
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe ...
- mysql添加远程用户
-- 增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询.插入.修改.删除的权限. -- 首先用以root用户连入MYSQL,然后键入以下命令: grant selec ...
- Openlayer 3 最简单的弹出框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Ubuntu配置Samba
一.安装Ubuntu samba服务器 $ sudo apt-get install samba $ sudo apt-get install smbclient # Linux客户端测试用 二.创建 ...
- Oracle截取某字段前后字符串
创建测试表及数据 1 2 3 4 5 6 7 8 9 create table test (name varchar2(10)); insert into test values ('2-15') ...
- 分布式版本控制系统Git-----4.Git 常用命令整理
1. git init 初始化 git 目录 2. git add 添加文件 git add fileName #添加指定文件 git add -i #手工选择要添 ...