IOS/ Storyboard : Create Outlet Property for Text of Tabbar Item on Toolbar

标签 ios storyboard uitabbarcontroller

我使用 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/

相关文章:

Javascript 返回不适合 UIWebView 给定宽度和高度的内容/字符串

ios - 在使用 Storyboard 和 segue 时打开它之前选择 tabbarcontroller 的默认选项卡

iphone - 如何确定哪个标签栏索引是我的 View Controller

iphone - 关闭两个模态(表) View Controller

ios - 均匀间隔多个 View 使用尺寸等级

iphone - 使用 Storyboard时单元测试 cellForRowAtIndexPath

ios - 如果它在 TabBarController 中,如何从 AppDelegate 访问 ViewController 的属性?

ios - 如何将字典插入数组

ios - UITextView 滚动时不显示全文

ios - 用默认值替换自定义后退按钮