主要是取得导航栏的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导航栏主题的更多相关文章

  1. IOS开发中设置导航栏主题

    /** * 系统在第一次使用这个类的时候调用(1个类只会调用一次) */ + (void)initialize { // 设置导航栏主题 UINavigationBar *navBar = [UINa ...

  2. [iOS微博项目 - 1.1] - 设置导航栏主题(统一样式)

    A.导航栏两侧文字按钮 1.需求: 所有导航栏两侧的文字式按钮统一样式 普通样式:橙色 高亮样式:红色 不可用样式:亮灰 阴影:不使用 字体大小:15   github: https://github ...

  3. IOS 导航栏属性设置

    IOS 7 以上系统导航栏: [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // 返回按钮颜色 [UINaviga ...

  4. 【Swift】iOS导航栏错乱的原因

    #iOS开发高级技巧#导航栏错乱,也就是导航栏的显示效果与内容区不匹配,引发原因很多,其中最重要的有两个原因: 1.在viewwillappear,viewwilldisappear两个函数中,设置导 ...

  5. 转:ios导航栏设置

    原帖:http://www.cocoachina.com/industry/20131104/7287.html 本文提供的代码需要用Xcode 5来执行.如果你还在使用老版本的Xcode,那么在运行 ...

  6. iOS导航栏背景,标题和返回按钮文字颜色

    在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...

  7. iOS 导航栏黑线,UIImage 枚举处理方式

      ios 找出导航栏下面的黑线(可隐藏,改变样式等) http://www.jianshu.com/p/effa4a48f1e3     设置UIImage的渲染模式:UIImage.renderi ...

  8. ios 导航栏的显示和隐藏切换

    从简单的一个没有导航栏的界面A push到另一个有导航栏的界面 B,在界面A的逻辑中加入下面逻辑: 屏幕快照 2016-03-30 上午10.35.24.png 这样完美的处理了这个场景变换需求.引起 ...

  9. iOS导航栏的正确隐藏方式【转】

    简介:在项目中经常碰到首页顶部是无限轮播,需要靠最上面显示.有的设置导航栏为透明等一系列的方法,这个可以借助第三方.或者干脆简单粗暴的直接隐藏掉导航栏.可是push到下一个页面的时候是需要导航栏的,如 ...

随机推荐

  1. Java处理JPEG图片时,需要导入com.sun.image.codec.jpeg.JPEGImageEn,报错处理

    Java处理JPEG图片时,需要导入com.sun.image.codec.jpeg.JPEGImageEn,会报错,不能使用相应的方法. 原因:java访问限制级api的时候,默认的eclipse设 ...

  2. 百度地图api写在html上可以实现,在jsp上会出现Bmap未定义的问题

    在html上引用时用:<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0& ...

  3. 生成元(Digit Generator,ACM/ICPC Seoul 2005,UVa 1583)

    #include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int t, n, a, ...

  4. jx problem

    Entity: line 37: parser error : xmlParseEntityRef: no nameecho "xxxxxx > /dev/null 2>& ...

  5. How to use php serialize() and unserialize()

    A PHP array or object or other complex data structure cannot be transported or stored or otherwise u ...

  6. xss框架的一些想法

    今天pybeef作为一个课程设计答辩完成了,向老师介绍了很多xss利用相关的场景和技术. 先说一下已经实现了什么, 1, 浏览器版本的判断 这方面只能判断IE和firefox 火狐判断只判断了user ...

  7. PIE使用阴影后的背景透明方法

    使用PIE后,会发现如果有设置 box-shadow 时,当前 class 样式中设置 opacity 或者背景渐变透明都会无效了,其实也是有办法解决的 css3-container { filter ...

  8. How to solve java.net.SocketTimeoutException:60000millis problem in HDFS

    Many HDFS users encounter the following error when DFSClient ready file from a certain Data Node.  & ...

  9. iOS开发关于xcode中souceControl的苹果文档翻译(节选)

    Subversion 1.7 provides many benefits: svn1.7版本有以下好处: Improved performance. Increased speed for many ...

  10. html5权威指南:表格元素

    第十一章:表格元素                                                                                           ...