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] > ...
随机推荐
- 606. Construct String from Binary Tree 从二叉树中构建字符串
[抄题]: You need to construct a string consists of parenthesis and integers from a binary tree with th ...
- SUSE Linux 多路径软件+LVM+裸设备的配置
1.先要查出光纤卡的WWN号,SUSE 10下光纤卡的WWD在/sys/class/fc_host/host5/port_name文件中,有两块卡就会有两个host*的目录 接好光纤后可以在dev下可 ...
- 处理事件冒泡,阻止默认事件工具类,兼容IE
//处理事件冒泡,阻止默认事件工具类,兼容IEvar eventUtil={ // 添加句柄 addHandler:function(element,type,handler){ if(element ...
- 使用python把图片存入数据库-乾颐堂
一般情况下我们是把图片存储在文件系统中,而只在数据库中存储文件路径的,但是有时候也会有特殊的需求:把图片二进制存入数据库. 今天我们采用的是python+mysql的方式 MYSQL 是支持把图片存入 ...
- 1、概率vs统计
- 浅谈css float
相信许多许多Web前端的朋友一定被float这个属性给困扰过吧,有时候用它来布局很方便,能够实现元素快速的水平排列,但有时候它又像一个精灵,让人无法琢磨透它方位.在网上也看了一些关于float的帖子, ...
- block functions区块函数插件的定义与使用
在插件目录plugins里新建文件 block.插件名.php文件(如 block.插件名.php) 例:block.test2.php <?php function smarty_block_ ...
- UVa 12099 The Bookcase (DP)
题意:有 n 本书,每本书有一个高度和宽度,然后让你制作一个3层的书架,可以放下所有的书,并且要高*宽尽量小. 析:先把所有的书按高度进行排序,然后dp[i][j][k] 表示 前 i 本书,第二 层 ...
- SpringMVC源码解读 - HandlerMapping - SimpleUrlHandlerMapping初始化
摘要: SimpleUrlHandlerMapping只是参与Handler的注册,请求映射时由AbstractUrlHandlerMapping搞定. 初始化时,通过setMappings(Prop ...
- Alpha冲刺(四)
Information: 队名:彳艮彳亍团队 组长博客:戳我进入 作业博客:班级博客本次作业的链接 Details: 组员1(组长)柯奇豪 过去两天完成了哪些任务 文章基本的存储.列表生成显示 展示G ...






