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
著做權歸做者全部,轉載請聯繫做者得到受權,並標註「簡書做者」。字體