self.navigationController?.navigationBar.hidden = false
这里要注意一点,navigationBar在页面中是与基View平级的,因此若是导航栏一开始是隐藏的,当页面加载完毕又想让他显示,这时候会发现基页面总体向下移动了,而且原来的内容会有一部分显示不完整!通过调试发现,若是不隐藏导航栏,基view的高度是屏幕高度与导航栏高度的差;若是隐藏了导航栏,基view的高度就是整个屏幕的高度。因此一开始隐藏了导航栏,页面加载完成再显示,就须要把基view的高度减去导航栏的高度!swift
//backgroundColor 是最底下的color self.navigationController?.navigationBar.backgroundColor = UIColor.redColor()
//barTintColor 是表层颜色 self.navigationController?.navigationBar.barTintColor = UIColor.grayColor()
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blueColor(),NSFontAttributeName:UIFont(name: "Heiti SC", size: 24.0)!]
//彻底隐藏backItem// self.navigationItem.setHidesBackButton(true, animated: true)
swiftself.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blueColor(),NSFontAttributeName: UIFont(name: "Chalkduster", size: 13)!], forState: UIControlState.Normal)
//从新定义backItem,将覆盖原来的BackItem.与storyboard中拖入一个item,效果同样。都是覆盖原来的backitem。 //第一种代码定义方式 self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "function"), animated: true) //第二种代码定义方式 self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "function") //第三种代码定义的方式 self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(title: "<Grandre", style: UIBarButtonItemStyle.Plain, target: self, action: "function"), animated: true)
//将导航栏设置成透明 self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default) self.navigationController!.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.translucent = true
若是对你有帮助,记得mark一下哦!ide
文/ChinaSwift(简书做者)
原文连接:http://www.jianshu.com/p/738d9387ed12/comments/1185395
著做权归做者全部,转载请联系做者得到受权,并标注“简书做者”。字体