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] > ...
随机推荐
- 新手教程: 如何在新浪云计算SAE里部署代码
感谢 sou6 的投递 时间:2011-11-22 来源:老夏博客 SAE自2011-7-10日起,全面支持SVN代码部署,用户不仅可以通过任何SVN客户端部署代码,而且SAE现有的代码部署方式也已经 ...
- LVS集群中实现的三种IP负载均衡技术
LVS有三种IP负载均衡技术:VS/NAT,VS/DR,VS/TUN. VS/NAT的体系结构如图所示.在一组服务器前有一个调度器,它们是通过Switch/HUB相连接的.这些服务器 提供相同的网络服 ...
- js setTimeout 和 setInterval 区别
setTimeout和setInterval的语法相同.它们都有两个参数,一个是将要执行的代码字符串,还有一个是以毫秒为单位的时间间隔,当过了那个时间段之后就将执行那段代码.不过这两个函数还是有区别的 ...
- Nmap扫描参数解析
Nmap是一款开源免费的网络发现(Network Discovery)和安全审计(Security Auditing)工具.软件名字Nmap是Network Mapper的简称.Nmap最初是由Fyo ...
- python3--多目录之间的协作的一些必备知识
# Auther: Aaron Fan # 动态获取执行文件的相对路径路径:print(__file__) #动态获取执行文件的绝对路径:import osfile_path = os.path.ab ...
- 掌握所有IO口的外部中断
外部中断配置流程 1.初始化IO口工作在普通IO.上拉输入状态. 2.首先开IO口组中断(P0IE=1.P1IE=1.P2IE=1): 3.开组内对应的具体某IO口中断(P0IEN.P1IEN.P2I ...
- C# WebService中任务处理线程创建子线程后
protected void WriteLog(string message) { lock (lockObject) { var file = System.IO.File.AppendText(& ...
- 浏览器透明设置例子,qt5.6才支持
用simpleBrowser例子的基础上,在BrowserWindow构造函数修改如下 BrowserWindow::BrowserWindow(QWidget *parent, Qt::Window ...
- SSH不能连接虚拟机中的Ubuntu
设置 网络 既然要远程ubuntu的系统.那么首先是两个网络是不是在一个网段.能不能ping的通? a) Windows电脑上--cmd 打开命令窗口.键入:ipconfig 命令.查看主机IP. b ...
- Linux 下几个重要目录解释
linux下把所有的东西都当作文件的,,一个分区想要使用就需要挂载到一个文件夹上,那这个文件夹就叫挂载点,像常用的把 设备/dev/cdrom挂载到/mnt,,,你想问的应该是linux的各目录的解释 ...






