默认情况下,导航后退按钮文本显示为上一个屏幕标题或<
我正在尝试将其更改为< = |
但它的到来如图所示 BackButton Image. 所以,我想知道如何更改其字体以使大< = |并删除默认的<
我试过
在第一个开始屏幕的viewDidLoad中尝试了相同的代码, 所以我也想知道在哪里放置这段代码:
override func viewWillAppear(animated: Bool)
{
self.navigationItem.leftBarButtonItem?.title = "<=|"
let FntStgVal = [NSFontAttributeName:UIFont.systemFontOfSize(50, weight: UIFontWeightLight)]
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes(FntStgVal, forState: .Normal)
}
答案 0 :(得分:2)
在viewDidLoad
中更改您的代码。
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
func setNavigationWithCustomBackButton() {
let btnLeft:UIButton! = UIButton(frame: CGRectMake(0, 0, 20, 16))
btnLeft.setTitle("<=|", forState: .Normal)
btnLeft.titleLabel?.font = UIFont.systemFontOfSize(19, weight: UIFontWeightLight)
btnLeft!.addTarget(self, action: "handleBack:",forControlEvents: UIControlEvents.TouchUpInside)
let leftItem:UIBarButtonItem = UIBarButtonItem(customView: btnLeft!)
self.navigationItem.leftBarButtonItem = leftItem
}
func handleBack(sender: UIButton) {
self.navigationController?.popViewControllerAnimated(true)
}
}
现在使用此BaseViewController
作为您所有viewController
的父级,并在此viewDidLoad
中调用其方法。
class ViewController1: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.setNavigationWithCustomBackButton()
}
}
现在它会在NavigationBar
中添加自定义后退按钮。
希望这会对你有所帮助。