闲来无事便在网上google&baidu了一番UINavigationController的相关文章,然后又看了下官方文档;看看更新到iOS7之后UINavigationController的是否有变化,同时也再温故下UINavigationController的使用0.0 平时都是用的自定义的导航栏别到时连系统自己的都不会用了-。-
  这里不介绍UINavigationController的使用,其实这个大部分情况下也只是用于页面的跳转就好了;现在我就记录一些平时没怎么注意到的和还蛮重要的属性,加之理一下层次关系;主要作用还是为了自己不记得时好查看一下好了0.0
  一般来说应该是UINavigationController包含UINavigationBar和UIToolbar;然后UINavigationBar中又包含了若干个UINavigationItem;UIToolbar也包含如干个UIBarButtonItem的。这个确实如此,不过在UIViewController的扩张类中有navigationItem和toolbarItems的属性可以管理UINavigationController里面定义的UINavigationItem和UIToolbar。
  注意:这里UIBarButtonItem是专门针对一个的UIToolbar或者UINavigationBar对象放置在一个按钮。
  navigationBar默认 是显示的,而toolbarHidden则是默认隐藏的,如需更改显示状态的话可以调用以下代码来实现,这两个都是UINavigationController下定义的属性,同时也有对应的设置方法的。
代码中设置:
  self.navigationController.navigationBarHidden = YES;
self.navigationController.toolbarHidden = NO;
  
 
 


 下面根据不同的对象来介绍UINavigationController相关的一些类:

  //UINavigationBar
  好吧,到现在为止在使用UINavigationController的时候我是很少很少使用到UINavigationBar来进行相关设置的,很多的时候都是直接跳过self.navigationItem来管理的。不过在使用系统NavgationController的时候有些属性还是很有用的,记录下:
//titleTextAttributes(ios5.0以后可用)这是UINavigationBar的一个属性,通过它你可以设置title部分的字体、字号、阴影等
@property(nonatomic,copy) NSDictionary *titleTextAttributes NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; //UINavigationBar的这个属性可以设置navigation的内容和其中的按钮的颜色
@property(nonatomic,retain) UIColor *tintColor; 代码调用:
  NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor redColor] forKey:UITextAttributeTextColor];
self.navigationController.navigationBar.titleTextAttributes = dict;
self.navigationItem.hidesBackButton = YES; self.navigationController.navigationBar.tintColor = [UIColor greenColor];
 
  //UINavigationItem
  通常情况下我们在某个视图控制器中会通过self.navigationItem来管理系统的UINavigationController中的导航栏中的内容,UINavigationItem下的很多属性都是很常会用到的:
@property(nonatomic,copy)   NSString        *title;     //导航栏的标题
@property(nonatomic,retain) UIView *titleView; //导航栏的自定义视图,设定之后title就没效果了
@property(nonatomic,copy) NSString *prompt; //设置了这个属性值之后,导航栏会加高30,在导航栏标题上方显示该值
@property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem;//自定义导航栏的左按钮,默认是返回按钮
@property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;//自定义导航栏的左按钮,默认是没有东西显示 //代码示例如下
self.navigationItem.title = @"Root"; //设置标题,其实效果和self.title = @"Root";差不多
self.navigationItem.prompt =@"prompt test"; //在导航栏中添加segment
NSArray *array = [NSArray arrayWithObjects:@"12",@"34", nil];
UISegmentedControl *segmentedController = [[UISegmentedControl alloc] initWithItems:array];
segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;
[segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segmentedController; //左按钮
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(selectLeftAction:)];
self.navigationItem.leftBarButtonItem = leftButton; //右按钮
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(selectRightAction:)];
self.navigationItem.rightBarButtonItem = rightButton; //下面这两个属性设置可同时设置多个左、右按钮,设置方法和单个的差不多,只是先给归类到一个数组中;不过最好不要和设置单个的混合使用
@property(nonatomic,copy) NSArray *leftBarButtonItems NS_AVAILABLE_IOS(5_0);//设置多个左按钮,从左往右排列
@property(nonatomic,copy) NSArray *rightBarButtonItems NS_AVAILABLE_IOS(5_0);//设置多个左按钮,从右往左排列 代码示例:
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:leftButton,leftButton1, nil];
 
  //UIToolbar
  一般我们也都是没用这个系统的工具栏的,不过这里也列一下好了0.0
  UIToolbar一些属性我们也基本没使用,差不多就看作是存放多个UIBarButtonItem的容器好了,同时也大多使用UIViewController的扩张属性toolbarItems来管理好了,直接跳过UIToolbar。
  使用的时候先要设置显示工具栏,默认是隐藏的额,然后就可以加入多个UIBarButtonItem了,一般当UIButton使用好了
//代码示例:

self.navigationController.toolbarHidden = NO;

UIBarButtonItem *one = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
UIBarButtonItem *two = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];
UIBarButtonItem *three = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
UIBarButtonItem *four = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil];
//这个可使UIBarButtonItem自适应排列
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self setToolbarItems:[NSArray arrayWithObjects:flexItem, one, flexItem, two, flexItem, three, flexItem, four, flexItem, nil]];
 
 
 

系统UINavigationController使用相关参考的更多相关文章

  1. atitit.短信 验证码  破解  v3 p34  识别 绕过 系统方案规划----业务相关方案 手机验证码  .doc

    atitit.短信 验证码  破解  v3 p34  识别 绕过 系统方案规划----业务相关方案 手机验证码  .doc 1. 手机短信验证码 vs 图片验证码 安全性(破解成本)确实要高一些1 1 ...

  2. 使用VIRTUALBOX安装ANDROID系统 | 图文教程 | 相关设置

    使用VIRTUALBOX安装ANDROID系统 | 图文教程 | 相关设置 http://icaoye.com/virtualbox-run-android/

  3. Linux显示目前与过去登入系统的用户相关信息

    Linux显示目前与过去登入系统的用户相关信息 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ last youhaido pts/0 :0 Sat Jan 2 ...

  4. last 列出登入系统的用户相关信息

    Linux last 命令介绍 功能说明:列出目前与过去登入系统的用户相关信息. 语法:    last [-adRx][-f <记录文件>][-n <显示列数>][帐号名称. ...

  5. Linux系统运维相关的面试题 (问答题)

    这里给大家整理了一些Linux系统运维相关的面试题,有些问题没有标准答案,希望要去参加Linux运维面试的朋友,可以先思考下这些问题.   一.Linux操作系统知识 1.常见的Linux发行版本都有 ...

  6. Linux系统之网络相关的命令

    Linux系统之网络相关的命令 网络概述 网络:通过通信介质和通信设备 将分布不同地点的两台或多台计算机,经过相应的程序实现通信switch 交换机router 路由器网络的功能:数据通信:利用网络传 ...

  7. Android开发之深入理解Android 7.0系统权限更改相关文档

    http://www.cnblogs.com/dazhao/p/6547811.html 摘要: Android 6.0之后的版本增加了运行时权限,应用程序在执行每个需要系统权限的功能时,需要添加权限 ...

  8. JAVA如何利用Swiger获取Linux系统电脑配置相关信息

    最近开发java应用程序,涉及到获取Linux服务器相关配置的问题,特地网上搜寻了下,采用Swiger包可以直接获取,再次小结一下,以便于以后能方便使用,也便于其他童鞋们学习. 推荐大家参考链接:ht ...

  9. Dubbo -- 系统学习 笔记 -- 配置参考手册

    Dubbo -- 系统学习 笔记 -- 目录 配置参考手册 <dubbo:service/> <dubbo:reference/> <dubbo:protocol/> ...

随机推荐

  1. xps 文件操作笔记

    1. 在 Silverlight 显示XPS文件,参考:http://azharthegreat.codeplex.com/ 2. Word,Excel, PPT 文件转换为XPS: 参考一(老外写的 ...

  2. Lambda应用设计模式

    前言 在使用 Lambda 表达式时,我们常会碰到一些典型的应用场景,而从常用场景中抽取出来的应用方式可以描述为应用模式.这些模式可能不全是新的模式,有的参考自 JavaScript 的设计模式,但至 ...

  3. [游戏模版9] Win32 半透明 图像处理

    >_<:Previous part we talk about how to map a transparent picture, and this time we will solve ...

  4. HTTP协议之chunk编码(分块传输编码

    Transfer-Encoding: chunked 表示输出的内容长度不能确定,普通的静态页面.图片之类的基本上都用不到这个. 但动态页面就有可能会用到,但我也注意到大部分asp,php,asp.n ...

  5. atitit.提升开发效率---使用服务器控件生命周期 asp.net 11个阶段 java jsf 的6个阶段比较

    atitit.提升开发效率---使用服务器控件生命周期  asp.net 11个阶段  java jsf 的6个阶段比较 如下列举了服务器控件生命周期所要经历的11个阶段. (1)初始化-- --在此 ...

  6. Java面向对象概述

    一.什么是面向对象? 现实世界中,随处可见的一种事物就是对象,对象是事物存在的实体,如人类.书桌.计算机.高楼大厦等.人类解决问题的方式总是将复杂的事物简单化,于是就会思考这些对象都是由哪些部分组成的 ...

  7. 微信小程序笔记(二)

    微信小程序环境搭建与开发工具介绍 2-1 开篇介绍及下载工具 1.开发工具下载地址:   http://t.cn/RVKH0HS 2.下载安装对应版本:win32,win64,mac; 2-2 小程序 ...

  8. wicket基本控件使用笔记

    Label       new Label(“message”,”message content”); MutLineLabel         new MutlineLabel(“message”, ...

  9. Leetcode 203 Remove Linked List Elements 链表

    去掉链表中相应的元素值 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next ...

  10. Windows下提升进程权限

    windows的每个用户登录系统后,系统会产生一个访问令牌(access token) ,其中关联了当前用户的权限信息,用户登录后创建的每一个进程都含有用户access token的拷贝,当进程试图执 ...