【发布时间】:2016-05-19 09:28:01
【问题描述】:
我正在使用 Swift 2.2 开发应用程序。现在我想更改某个视图的后退按钮字体和颜色。有问题的视图有一个导航控制器,因为它是父控制器。
我尝试在 ViewController 的 viewDidLoad 中运行以下两行
self.navigationController!.navigationItem.backBarButtonItem!.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Andes Rounded", size: 17)!], forState: .Normal)
self.navigationItem.backBarButtonItem!.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Andes Rounded", size: 17)!], forState: .Normal)
两者都不会引发任何错误,但对后退按钮没有任何影响。我也尝试过运行这两个
self.navigationController!.navigationItem.leftBarButtonItem!.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Andes Rounded", size: 17)!], forState: .Normal)
self.navigationItem.leftBarButtonItem!.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Andes Rounded", size: 17)!], forState: .Normal)
然而,这会引发错误(错误展开 nil)。我应该如何正确更改导航栏后退按钮的字体和颜色?感觉好像我没有修改正确的项目...
【问题讨论】:
-
在
viewWillAppear:方法中设置您的navigationBar 的tintColor 并在viewWillDisappear:方法中重新设置 -
如果你想在整个应用中生效,请使用 appdelegate
didFinishLaunchingWithOptions中的代码
标签: ios swift swift2 uinavigationbar