How can I change the font of the back button for my navigation bar?

后端 未结 6 1362
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 03:02

How can I change the font of the back button for my navigation bar.

The back button is either \"back\" or the title from the previous view controller.

I tho

6条回答
  •  北海茫月
    2020-11-29 03:30

    When you are sure you've already set a UIBarButtonItem you can do:

    self.navigationItem.leftBarButtonItem!.title = "myTitle"
    

    To change e.g. the color you can do the following:

    self.navigationItem.leftBarButtonItem!.tintColor = UIColor.redColor()
    

    When you haven't set it in your storyboard you can do:

    self.navigationItem.leftBarButtonItem = UIBarButtonItem()
    

    For changing the font, do the following:

    self.navigationItem.leftBarButtonItem!.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "FONTNAME", size: 20)!], forState: .Normal)
    

    Maybe I should mention that you mustn't use self.navigationController because when setting the navigationController's buttons they aren't displayed on the screen so as a result the buttons which are on the screen and had been set in the storyboard have to be self.navigationItem...

提交回复
热议问题