How to programatically change titles of tabs in UITabBarViewController and here is how to programatically change title of individual View Controllers at Navigation Bar inside individual UITabBarViewControllers.

Let’s assume you are using Tab Bar View Controller in your Xcode Apple iOS App Project.

 
You have embedded in your view controller with UITabBarViewController.

 
Say, you are using 3 Tab Views.

 
In Swift programming Language number counting starts with 0 so you will write code like this in your respective view controller’s viewDidLoad function.

 

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.

self.tabBarController?.tabBar.items?[0].title = "tab 1"
self.tabBarController?.tabBar.items?[1].title = "tab 2"
self.tabBarController?.tabBar.items?[2].title = "tab 3"
}

 
Now you have given title to your tabs in your UITabBarViewController.

 
But now your want to give View Controller Title in Navigation Bar at the top.

 

Note: I assume you have already embedded in your Tab Bar View Controller with Navigation Bar.

 
So now you will write code like this in your current View Controller’s viewWillAppear function like this.

 

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.navigationItem.title = "tab 1 VC Title"
}

 
I hope it helps.

 
Thanks & Regards
Mandar Apte

Mandar Apte

This website contains a design articles blog by Mandar Apte. He writes and shares his iOS development, graphic, web, & animation film design experience through articles. Mandar is Mumbai based multi-disciplinary designer with expertise in UI, UX, Logo, Symbol, and Brand Identity design. He is an alumnus of Sir J. J. Institute of Applied Art, Mumbai. He currently runs his studio in the heart of the city of Mumbai.

Leave a Reply

Your email address will not be published. Required fields are marked *