I set an arrow custom image to navigation bar by adding the following code in app delegate, it works but now im looking to remove the text completely for back button.
UIImage * backButtonImage = [UIImage imageNamed: @"BackButtonGrey.png"];
backButtonImage = [backButtonImage stretchableImageWithLeftCapWidth: 15.0 topCapHeight: 30.0];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage: backButtonImage forState: UIControlStateNormal barMetrics: UIBarMetricsDefault];
I really don't think is a good practice for a developer to adjust the offset of the text in order to hide it.
A cleaner solution would be to just add to the navigation controller back button a new button where the title is an empty string. You should add this in the previous calling view controller in viewWillAppear (not the current one):
Do not use the appearance proxy. Instead, for every view controller, put this code into its
viewDidLoad
implementation:That will cause the next view controller pushed onto the navigation stack to have a back button consisting of just the image.
(However, I should point out that
stretchableImageWithLeftCapWidth:...
is deprecated. You should be usingresizableImage...
.)To set a backbutton text, you set a new backbutton to the current viewController before pushing or presenting then new one which would show the text of the backbutton:
In your current viewController (not the new one which will show the back-button):
So if you want to remove the text, just use
@""
as a title for the new backbutton.To set a backbutton-icon for the entire app, use the following code in your appDelegate class. Not every icon fits perfectly, so if you have to move it around a little, you can use the "backInsets". In my example the icon will move 2px down.
Tested with iOS9
Simply move the text vertically so far that it no longer appears. This can be done at app launch in your app delegate.
Normally this call is for tweaking the vertical text position which can vary depending on the font used. Here the text is moved far enough that it's no longer inside the Back button view, and so is clipped into non-existence.