Swift_ios_開發(fā)之UINavigationController的常用屬性那些事
1.導(dǎo)航欄是否隱藏 self.navigationController?.navigationBar.hidden = false 2.導(dǎo)航欄的最底部顏色設(shè)置 //backgroundColor 是最底下的color self.navigationController?.navigationBar.backgroundColor = UIColor.redColor() 3.導(dǎo)航欄
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冷溶,將覆蓋原來的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)
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