我正在尝试向我的标签栏项添加标题,但未显示不知道为什么
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
}
这是我正在使用此方法的viewDidload
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"))
]
输出
为导航控制器中的嵌入式控制器设置setupBarBarItem。
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
}