Search code examples
iosswiftuitabbarcontrolleruitabbaruitabbaritem

TabBar is not showing TabBar Item title Swift 5


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


Solution

  • 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