1.0 自定義UINavigationController時,背景圖片、顏色等只需要設置一次,所以我們可以重寫 initializa 這個方法來實現我們想要的效果
override class func initialze(){
let navBar = UINavigationBar.appearence()
navBar.barTintColor = UIColor.redColor() // 設置導航欄背景顏色 為紅色
var attrs = [String : AnyObject]()
attrs[NSFontAttributeName] = UIFont.systemFontOfSize(15)
attrs[NSForegroundColorAttributeName] = UIColor.whiteColor()
navBar.titleTextAttributes = attrs // 設置導航欄標題顏色 和 字體大小
// 設置導航欄背景圖片
navBar.setBackgroundImage(UIImage(named: "tabbar_home"), forBarMetrics: .Default)
//navBar.setBackgroundImage(UIImage(named: "tabbar_discover"), forBarPosition: .Any, barMetrics: .Default)
let navItem = UIBarButtonItem.appearance() // 獲取全局的BarButtonItem
navBar.backItem?.leftBarButtonItem?.customView?.backgroundColor = UIColor.whiteColor()
navBar.tintColor = UIColor.whiteColor() // 全局設置 BarButtonItem 的顏色 為白色
navItem.setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Default) // 通過設置把系統的自帶的返回字切掉,保留返回的指示圖標
注:單一設置導航欄的背景顏色時,控制器view的原點不會向下移動 64 ,當設置導航欄的背景圖片時,控制器的view的原點從導航欄下方開始,也就是向下移動 64
}