Search code examples
swinguinavigationitem

Navigation Bar Back Button Arrow Font Swift


So I manage to change the font of the back button as said in this post but now I have two arrows(<), one is the back button default arrow and the other is the button title arrow ("< Back").

How do I remove/change the back button default arrow to the font want?


Solution

  • One way is to create a transparent graphic and set it as the background image of your Backbutton. So your code should look like this:

        let backButton = UIBarButtonItem(title: "< back", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
        backButton.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "RobotoCondensed-Light", size: 20)!], forState: UIControlState.Normal)
        backButton.setBackButtonBackgroundImage(UIImage(named: "transparent_1px.png"), forState: UIControlState.Normal, barMetrics: UIBarMetrics(rawValue: 0)!)
        navigationItem.backBarButtonItem = backButton