我正在尝试添加标题到我的选项卡栏项,但它没有显示不知道为什么
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"))
]输出

发布于 2020-05-06 07:28:48
将其放入视图控制器- viewDidLoad()
self.title = “title“
self.tabBarItem.image = UIImage(named: “tabImage“)
self.tabBarItem.selectedImage = UIImage(named: “tabSelected”)你也可以通过故事板做到这一点。在导航控制器中选择Tab栏项,然后转到属性检查器并输入标题。

发布于 2020-05-06 03:39:04
在导航控制器中设置嵌入式控制器的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
}https://stackoverflow.com/questions/61625147
复制相似问题