轉(zhuǎn)載自網(wǎng)絡(luò)腰池,并重新梳理
1.導(dǎo)航欄是否隱藏
self.navigationController?.navigationBar.hidden = false
2.導(dǎo)航欄的最底部顏色設(shè)置
//backgroundColor 是最底下的color
self.navigationController?.navigationBar.backgroundColor = UIColor.redColor()
3.導(dǎo)航欄的表層顏色尾组,即首先看到的顏色
//barTintColor 是表層顏色
self.navigationController?.navigationBar.barTintColor = UIColor.grayColor()
4.導(dǎo)航欄中間標(biāo)題title的顏色,大小示弓,字體設(shè)置
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blueColor(),NSFontAttributeName:UIFont(name: "Heiti SC", size: 24.0)!]
5.導(dǎo)航欄隱藏左邊backitem讳侨,即leftbarbuttonitem
//完全隱藏backItem//
self.navigationItem.setHidesBackButton(true, animated: true)
6.導(dǎo)航欄leftbarbuttonitem的顏色設(shè)置
swiftself.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
7.導(dǎo)航欄leftbarbuttonitem的字體,顏色奏属,大小設(shè)置
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blueColor(),NSFontAttributeName: UIFont(name: "Chalkduster", size: 13)!], forState: UIControlState.Normal)
8.導(dǎo)航欄重新定義leftbarbuttonitem
//重新定義backItem跨跨,將覆蓋原來(lái)的BackItem.與storyboard中拖入一個(gè)item,效果一樣囱皿。都是覆蓋原來(lái)的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: "XXX", style: UIBarButtonItemStyle.Plain, target: self, action: "function"), animated: true)
9.導(dǎo)航欄設(shè)置成透明
//將導(dǎo)航欄設(shè)置成透明
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController!.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true