0

i am try to add title to my tab bar items, but it is not showing don't know why

fileprivate func appenedVC(for rootViewController: UIViewController,tabBarTitle: String, image: UIImage) -> UIViewController {

    let navController = UINavigationController(rootViewController: rootViewController)
    navController.tabBarItem.title = title
    navController.tabBarItem.image = image
    rootViewController.navigationItem.title = title
    navController.navigationBar.prefersLargeTitles = true
    return navController
}

here is viewDidload where i am using this method

abBar.tintColor = UIColor(red: 0, green: 0.5690457821, blue: 0.5746168494, alpha: 1)
    tabBar.unselectedItemTintColor = .black


    viewControllers = [
        appenedVC(for: CategoryVC(), tabBarTitle: "Category", image: #imageLiteral(resourceName: "categoryFilled")),
        appenedVC(for: FeedbackVC(), tabBarTitle: "Feedback", image: #imageLiteral(resourceName: "feedbackIFilled"))
    ]

Output

screenshot

Umer Khan
  • 193
  • 12

2 Answers2

0

Setup tabBarItem for embedded controller in navigation controller.

  fileprivate func appenedVC(for rootViewController: UIViewController, tabBarTitle: String, image: UIImage) -> UIViewController {
    rootViewController.tabBarItem = UITabBarItem(title: title, image: image, selectedImage: image)
    rootViewController.title = tabBarTitle
    let navController = UINavigationController(rootViewController: rootViewController)
    navController.navigationBar.prefersLargeTitles = true
    return navController
  }
OrientCue
  • 1
  • 1
0

Put it in your view controller - viewDidLoad()

self.title = “title“
self.tabBarItem.image = UIImage(named: “tabImage“)
self.tabBarItem.selectedImage = UIImage(named: “tabSelected”)

You can do that through storyboard as well. Select the Tab bar item in your navigation controller and go to attribute inspector and enter the title.

enter image description here

Daljeet Seera
  • 188
  • 1
  • 10