我使用 TabBar Controller 作为导航的一部分。链接到 TabBar Controller 的 VC 具有导航 Controller ,其图标图像是您在选项卡栏中看到的图像,例如,主屏幕的主页图标。
我希望能够更改文本和可能的图标图像。一种自然的方法是创建一个 socket 属性,但我不知道将它连接到哪个 View Controller ,因为该图标似乎是导航 Controller 的一部分,而不是 VC 本身。我试过从图标拖动到由适当的导航 Controller 控制的 VC,但没有成功。
谁能建议如何完成这个?
感谢您的任何建议。
最佳答案
您可以在每个 View Controller 中设置选项卡栏项目图像/标题,例如在 viewDidAppear 中
if let selectedItem = self.tabBarController?.tabBar.selectedItem {
selectedItem.image = UIImage.init(named: "DefaultImageName")
selectedItem.selectedImage = UIImage.init(named: "SelectedImageName")
selectedItem.title = "Test Title"
}
关于IOS/ Storyboard : Create Outlet Property for Text of Tabbar Item on Toolbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49157457/