TabBar 未显示 TabBar 项目标题 Swift 5

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

在导航控制器中为嵌入式控制器设置 tabBarItem。

  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
  }

把它放在你的视图控制器中 - viewDidLoad()

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

您也可以通过情节提要来做到这一点。 Select 导航控制器中的选项卡栏项目,然后转到属性检查器并输入标题。