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

Leave a Reply

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