Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to globally change title of all navigtion bar back button to "Back"

Tags:

ios

It's tedious to change it in all view controller

Can I change it globally?

like image 855
allenwei Avatar asked Mar 21 '12 12:03

allenwei


People also ask

How do you change the title of a navigation?

Use navigationBarTitle(_:) to set the title of the navigation bar. This modifier only takes effect when this view is inside of and visible within a NavigationView .

How do I get rid of the back button on my navigation bar?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Full screen gestures”. The navigation bar will be hidden and you will be shown “Gesture demos” to explain how to operate the “Go back”, “Go to Home screen” and “Open Recents” functions.


1 Answers

What you can use is a category:

UINavigationItem+MyBackButton.h

@interface UINavigationItem (MyBackButton)

@end

UINavigationItem+MyBackButton.m

#import "UINavigationItem+MyBackButton.h"

@implementation UINavigationItem (MyBackButton)

-(UIBarButtonItem*)backBarButtonItem
{
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
                                   initWithTitle: @"Back Button Text" 
                                   style: UIBarButtonItemStyleBordered
                                   target: nil action: nil];

    return [backButton autorelease];
}
@end

Add this two files to the project and you are done. To be more efficient ivar and lazy loading should be added here.

like image 176
A-Live Avatar answered Oct 22 '22 01:10

A-Live