Programmatically change the titles of tabs in UITabBarViewController. Change the title of the Navigation Bar for each UITabBarViewController.

Let’s assume you use Tab Bar View Controller in your Xcode 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 the title to your tabs in your UITabBarViewController.

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

Note: I assume you have already embedded in your Tab Bar View Controller with the 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

Published by Mandar Apte

Mandar is a Mumbai-based multi-disciplinary designer with UX/UI, Logo, Symbol, and Brand Identity design expertise. He currently runs his Mudrkashar Linguistic Apple iPhone, iPad, and Mac app business in the heart of Mumbai city.

Leave a comment

Leave a Reply