如何更改“更多”导航栏背景和文字颜色以最有效的方式选项卡?
我在我的应用程序委托中使用以下 UINavigation 委托方法来更新所有视图控制器的导航栏背景和文本颜色(这样我就不必为堆栈中的每个视图控制器重复代码。
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
这对于除了“更多”选项卡之外,我现在在“更多”选项卡中拥有多个视图控制器
是否也可以为“更多”选项卡调用 UINavigation 委托方法?更改导航栏的最佳选择以及“更多”选项卡中所有视图控制器的文本颜色,而无需为所有视图控制器重复代码。
I am using the following UINavigation delegate method in my app delegate to update the navigation bar background and text color for all my view controllers (so that I do not have to repeat code for every view controller in the stack.
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
This has been working fine for all my tabs in the app except for the "more" tab. I now have more than one view controller in the 'more tab'
Is it possible to invoke the UINavigation delegate method for the 'more' tab as well? Else what is the best alternative to change the navbar and text color of all the view controllers in the more tab without repeating code for all the view controllers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要多次做同样的事情。我的解决方案是创建一个继承 UIViewController 的超类,然后在视图加载时自定义导航栏。然后用所有视图控制器继承这个超类。
该解决方案将所有自定义导航栏更改放在一个位置,因此如果您想更改颜色或添加图像,您只需在该超类中执行即可。这是继承和代码重用的一个很好的用途,它将使您的类没有重复的代码。
I've needed to do the same thing many times. My solution is to create a super class that inherits UIViewController and then customizes the nav bar in view did load. Then inherit this super class with all of your view controllers.
This solution puts all of your custom nav bar changes into one spot so if you want to change colors or add images you only have to do it in that one superclass. This is a great use of inheritance and code reuse which will keep your classes free of duplicated code.