1
votes

I have added a custom image for back button in the navigation bar. Here is the function for setting up my navigation bar.

func setUpNavBar() {
    self.navigationController?.navigationBar.isHidden = false
    self.navigationController?.navigationBar.tintColor = UIColor.black
    self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "BackArrow")
    self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "BackArrow")
    self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: nil, action: nil)   
}

The resulting nav bar with above settings is as shown below.

enter image description here

Next, I want to increase the spacing between the back icon and the text and also increase the text size (also make it bold). How can this be done?

1

1 Answers

1
votes

To change the size of the text and make it bold set the title textAttributes:

navigationItem.backBarButtonItem?.setTitleTextAttributes([NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 14)], for: .normal)

To edit the title offset you can use the following:

navigationItem.backBarButtonItem?.setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -10, vertical: 0), for: .default)