本文介绍了在uitabbarcontroller中更改选项卡名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个TabBarController设置为主控制器选项卡,其中名称是使用界面构建器定义的。现在我想以编程方式更改其名称。I have a TabBarController set as main controller tab, where names were defined using interface builder. Now I would like to change its names programmatically.如何实现?推荐答案 更新到XCode 8 由于我原来的答案,很多事情发生了:Swift 3,Storyboards等。标题通常是所有视图共享的,可以在属性检查器Updated to XCode 8Since my original answer, a lot has happened: Swift 3, Storyboards, etc. Title is usually the one that all views share, and can be set in the attributes inspector此外,为了更多控制,您可以随时拖动设计器视图中的In terms of reusability, you should be setting the title only from the inside of the UIViewController subclass.使用笔尖或故事板?如果你有一个 UIViewController ,你可以直接在属性检查器(或 4 )Using nibs or storyboards? If you have a UIViewController, you can give it the name straight up in the attributes inspector (or )不幸的是,如果文件所有者是 UIViewController 子类, t能够以这种方式访问​​它,只是因为,XCode注册文件所有者作为外部对象,并没有显示它的配置面板。 :(Unfortunately, if the File Owner is the UIViewController subclass, then you won't be able to access it this way, simply because, XCode registers the File Owner as an "External Object", and doesn't show a configuration panel for it. :(但有时候, / p>But sometimes, you just want to have them named differently// Modify the display title on the tab barself.tabBarItem.title = @"World";// Modify the display title on the navigation barself.navigationItem.title = @"Hello World"; 与邻居进行调整 每个UIViewController都应该处理自己的名称,如果你想从外部强制Screwing with the neighboursEach UIViewController should handle his own name, what if you want to force it from the outside (and thus, completely violating the original thing I said about reusability)?// Rename the other guy's .title property[[self.tabBarController.viewControllers objectAtIndex:<#Index#>] setTitle:@"Hello World"];// Or do as before, and rename the other guy's tab bar[(UITabBarItem*)[self.tabBarController.tabBar.items objectAtIndex:<#index#>] setTitle:@"Hello World"];您也可以使用导航项目,但这将需要更多的体操比我舒服。You could also probably do it with the navigation item, but that would require more gymnastics than I'm comfortable with. 这篇关于在uitabbarcontroller中更改选项卡名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 23:08
查看更多