默认的后退按钮文本和字体设置 [英] Default Back Button Text and Font Setting
问题描述
默认情况下,导航后退按钮文本作为上一个屏幕标题或<
By default, Navigation back button text comes as previous screen title or <
我正在尝试将其更改为< = |
I am trying to change that to just <=|
但是它来了,如图所示 BackButton图片. 因此,我想知道如何更改其字体以使< = |变大.并删除默认的<
But Its coming as shown in the picture BackButton Image. So, I want to know how to change its font to make big <=| and remove the default <
我尝试过
在第一个开始屏幕的viewDidLoad中尝试了相同的代码, 所以我也想知道将此代码放在哪里:
Tried the same code in viewDidLoad of first start screen, So i also want to know where to place this code:
override func viewWillAppear(animated: Bool)
{
self.navigationItem.leftBarButtonItem?.title = "<=|"
let FntStgVal = [NSFontAttributeName:UIFont.systemFontOfSize(50, weight: UIFontWeightLight)]
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes(FntStgVal, forState: .Normal)
}
推荐答案
像这样在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
中调用其方法.
Now use this BaseViewController
as parent of your all viewController
and call its method in viewDidLoad
like this.
class ViewController1: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.setNavigationWithCustomBackButton()
}
}
现在它将在NavigationBar
中添加自定义后退按钮.
希望对您有帮助.
Now it will add custom back button in your NavigationBar
.
Hope this will help you.
这篇关于默认的后退按钮文本和字体设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!