UINavigationController及顶部导航条
- UINavigationController管理一个VC的栈,栈底的VC叫做这个UINavigationController的root view controller.
- 有一个函数叫做
popToRootViewController(animated:),就是返回rootVC。 UINavigationController在顶部有一个
navigationBar,继承自UIView。它的frame,bound及alpha值都不能改变。隐藏或者显示这个navigationBar要调用UINavigationController的setNavigationBarHidden(_:animated:)方法。其中动画的时间是一个常量UINavigationControllerHideShowBarDuration,不能改变。To show or hide the navigation bar, you should always do so through the navigation controller by changing its isNavigationBarHidden property or calling the setNavigationBarHidden(_:animated:) method.
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationController?.navigationBarHiddennavigationBar的各个属性

navigationBar的背景色
self.navigationController?.navigationBar.barTintColor = UIColor.yellowColor()

navigationBar的配置
navigationBar有左、中、右三个部分。显示的具体内容是根据当前VC的UINavigationItem属性及栈中前一个VC的UINavigationItem属性配置的。UINavigationItem
UINavigationItem作为VC的属性,在这个VC处于navigation stack时,用来设置定于导航条的样式等等。属性分别用来设置导航条左、中、右的样式等。左边
- leftBarButtonItem 最左边的按钮
- leftBarButtonItems 最左边的按钮们(可以有多个)
- setLeftBarButtonItems(_:animated:)
self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "left", style: .Plain, target: self, action: #selector(TGVCButtom.leftButtonClicked(_:)))
self.navigationItem.leftBarButtonItem?.tintColor = UIColor.brownColor()
let dict = [NSForegroundColorAttributeName : UIColor.blueColor(),
NSKernAttributeName: NSNumber.init(int: 10)
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes(dict, forState: .Normal) let sencondleftBarButtonItem = UIBarButtonItem.init(title: "leftSecond", style: .Plain, target: self, action: #selector(TGVCButtom.secondLeftButtonClicked(_:)))
self.navigationItem.setLeftBarButtonItems([self.navigationItem.leftBarButtonItem!,sencondleftBarButtonItem], animated: true)

中间
title
self.navigationItem.title = "buttomVC"
titleView
会覆盖title。如果需要设置button、富文本可以考虑这个Custom title views are centered on the navigation bar and may be resized to fit
self.navigationItem.titleView = UIImageView.init(image: TGResizeImage(UIImage.init(named: "cat"), byRatio: 0.5) )
- 右边。和左边类似。
- rightBarButtonItem
- rightBarButtonItems
- setRightBarButtonItems(_:animated:)
返回按钮
有时候既要有一个返回的按钮,又要有一个左边的按钮。达到微信的网页常有的返回+关闭的效果。

假设一个当前VC是A,push一个VC出去。
self.navigationController?.pushViewController(self.topVC, animated:true)
那么需要
设置自己的backBarButtonItem
self.navigationItem.backBarButtonItem = UIBarButtonItem.init(title: "back", style: .Plain, target: nil, action: nil);
设置topVC的leftBarButtonItem
self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "leftButton", style: .Done, target: self, action: nil)
设置topVC的两个变量
self.navigationItem.hidesBackButton = false //返回按钮没有被隐藏
self.navigationItem.leftItemsSupplementBackButton = true //返回按钮可以和左边的按钮一起出现

奇怪的prompt
A single line of text displayed at the top of the navigation bar
self.navigationItem.prompt = "promt"//不知道干嘛的。。有啥用呢

如何禁止左滑返回
self.navigationController?.interactivePopGestureRecognizer?.enabled = false
UINavigationController及顶部导航条的更多相关文章
- uni-app自定义导航栏按钮|uniapp仿微信顶部导航条
最近一直在学习uni-app开发,由于uniapp是基于vue.js技术开发的,只要你熟悉vue,基本上很快就能上手了. 在开发中发现uni-app原生导航栏也能实现一些顶部自定义按钮+搜索框,只需在 ...
- HTML实例-02-京东顶部导航条
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- css实现京东顶部导航条
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...
- Bootstrap 固定在顶部导航条
@{ Layout = null;}<!DOCTYPE html><html><head> <meta name="viewport&q ...
- Bootstrap组件之响应式导航条
响应式导航条:在PC和平板中默认要显示所有的内容:但在手机中导航条中默认只显示“LOGO/Brand”,以及一个“菜单折叠展开按钮”,只有单击折叠按钮后才显示所有的菜单项. 基础class: .nav ...
- Swift - 导航条(UINavigationBar)的使用
与导航控制器(UINavigationController)同时实现导航条和页面切换功能不同. 导航条(UINavgationBar)可以单独使用,添加至任何的UIView中.UINavigation ...
- android开发(1):底部导航条的实现 | navigation tab | activity的创建
底部导航条,在iOS中叫tabbar,在android中叫bottombar或bottom navigation,是一个常用的切换页面的导航条. 同样,如果有良好的第三方库,我们应该优先考虑,能用好别 ...
- 基于jQuery实现页面滚动时顶部导航显示隐藏效果
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...
- UINavigationController导航条是否挡住下面的内容
控制 UINavigationController 导航条是否挡住下面的内容 if ([[[UIDevice currentDevice] systemVersion] floatValue] > ...
随机推荐
- DBArtist之Oracle入门第3步: 安装配置PL/SQL Developer
操作系统: WINDOWS 7 (64位) 数据库: Oracle 11gR2 (64位) PL/SQL Developer : PL/SQL ...
- 274. H-Index论文引用量
[抄题]: Given an array of citations (each citation is a non-negative integer) of a researcher, write a ...
- Ubuntu16.0安装Eclipse Neon
eclipse在Ubuntu下安装先安装jdk,配置环境变量,之后下载eclipse安装包,解压,放置在目标目录,将jre链接到该目录或者将jdk下的jre目录复制到eclipse安装包目录下,双击文 ...
- QuickSort模板
#include <iostream> using namespace std; struct node { int index; char name[20]; }; node data[ ...
- HTTP 499状态码 nginx下499错误详解-乾颐堂
日志记录中HTTP状态码出现499错误有多种情况,我遇到的一种情况是nginx反代到一个永远打不开的后端,就这样了,日志状态记录是499.发送字节数是0. 老是有用户反映网站系统时好时坏,因为线上的产 ...
- css3之transform-origin
transform-origin属性平时似乎用得很少,它决定了变换时依赖的原点.基本的属性特性可以参考CSS手册. 如果在H5动画项目中,用到旋转的话,它还是不能小觑的. 假如我们做一个秋千效果 其实 ...
- C/C++语言中的函数参数传参三种对比
学了很长时间C/C++有时指针方面还是有点乱. 希望大神发现如果下面有不对的地方请指出.我发现之所以我乱就是因为中文表述不准确的问题,比如 ,地址值和地址 #include <iostream& ...
- UVALive 7752 Free Figurines (瞎搞)
题意:给定 n 个盒子,然后告诉你每个盒子在哪个盒子里,数值越大,盒子越大,给定你初态,和末态,问你最少要几步能完成,只有两种操作,一种是把一个盒子连同里面的小盒子放到一个空盒子里,另一种是把一个堆盒 ...
- CodeForces 427B Prison Transfer (滑动窗口)
题意:给定 n, t, c 和 n 个数,问你在这 n 个数中有多少连续的 c 个数,并且这个 c 个数不大于 t. 析:很简单么,是滑动窗口,从第一个开始遍历,如果找到 c 个数,那么让区间前端点加 ...
- msf、armitage
msfconsole的命令: msfconsole use module :这个命令允许你开始配置所选择的模块. set optionname module :这个命令允许你为指定的模块配置不同的选项 ...






