UINavigationController定制
先设置整个app的导航栏的通用属性,自定义一个UINavigationController:
class RootNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
//设置导航栏背景颜色,只能用图片
navigationBar.setBackgroundImage(UIImage(named: "navibac")?.imageWithRenderingMode(.AlwaysOriginal), forBarMetrics: .Default)
//设置标题的字体颜色
navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor(white: 1.0, alpha: 1.0)]
//设置左右两边item的文字(图片)的颜色
navigationBar.tintColor = UIColor(r: 248, g: 160, b: 60)
}
}
在某个UIViewController设置特定的属性:
class HomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//设置左item的图片
navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "close"), style: UIBarButtonItemStyle.Plain, target: self, action:Selector("back"))
//设置右边item的文字和回掉函数
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "更多", style: .Plain, target: self, action: nil)
//设置标题
navigationItem.title = "Home"
}
func back(){
print("back")
}
}
效果图下:

I am not doing shit today !

浙公网安备 33010602011771号