Change UINavigationBar back button title
44,217
Solution 1
Do this in the parent view controller not in the child
Swift
navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: nil, action: nil)
Objetive-C
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
Solution 2
self.navigationController.navigationBar.topItem.title = @"";
Solution 3
If you are using storyboard you can select the navigation item in the parent view controller and set the button text you want in 'Back Button' field. Remember to set this in the parent view controller, not in the child that is pushed.
Solution 4
Try this hope it will be work
UIBarButtonItem *btn =
[[UIBarButtonItem alloc] initWithTitle:@"New Title"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:btn];
Solution 5
Back Button With Back Arrow
Objective-C
self.navigationController.navigationBar.topItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Title" style:UIBarButtonItemStylePlain
target:nil action:nil];
Swift
self.navigationController?.navigationItem.backBarButtonItem =
UIBarButtonItem(title:"Title", style:.plain, target:nil, action:nil)
Normal Button Without Back Arrow
Objective-C
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Title"
style:UIBarButtonItemStylePlain target:nil action:nil];
Swift
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:"Title",
style:.plain, target:nil, action:nil)
Bold Button Without Back Arrow
Objective-C
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Title"
style:UIBarButtonItemStyleDone target:nil action:nil];
Swift
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title:"Title",
style:.done, target:nil, action:nil)
Author by
S S
Updated on September 24, 2020Comments
-
S S over 3 years
In my application I want to use 'Back' text as back button title for every viewcontroller. I have read so many posts on stackoverflow but got nothing.
I don't want to set leftbarbuttonitem.
Can anyone help me on this simple task.
Thanks,
-
Gajendra Rawat about 10 yearsadd this line in view did load method from where you are switching next viewcontroller. like you are going to detailview controller(having back button) from master view controller then add it in masterview controller viewdidload method @SeemaSharma
-
Hamid Pourjam over 8 yearsWhile this code may answer the question, it is better to explain what it does and add some references to it.
-
sheetal about 8 yearsAwesome fix... Thanks
-
Mathias Claassen about 8 yearsIn my case
navigationController?.navigationBar.backItem?.title = ""
for back button -
rustylepord almost 8 yearsThe problem with this approach would be , lets say you have a home view controller with the title "Home" , Then you navigate to the second view controller which has the title "Child" , when you apply this , it will change the back button title , however when you go back, it will change the home screen title back button title . ;) unless you don't set it explicitly again .
-
rustylepord almost 8 yearsTested and worlds well iOS 9.3.2
-
Lucas over 6 yearsnavigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil) in Swift
-
Sergiob about 6 yearsThis is a much better solution
-
Radames E. Hernandez over 5 yearsThank you so much! this is so helpful for me
-
user25 about 5 yearsnothing changes, I've tried
viewDidLoad
andviewWillAppear
-
user25 about 5 yearsit changes tittle in the middle of bar not back button's title
-
user25 about 5 yearsit changes tittle in the middle of bar not back button's title
-
user25 about 5 yearsIt doesn't work. Where do you call it? I tried
viewDidLoad
andviewWillAppear
but nothing happens when it callsself.navigationController?.navigationBar.backItem?.title = "test"
-
andrew54068 about 4 yearshave to add code above in previous view controller.
-
Gonçalo Gaspar over 3 yearsThank you this solved a long time issue. Only one that worked.