简体   繁体   English

更改“更多”视图控制器的背景颜色

[英]Change the background color of “More” view controller

是否可以在UITabBarController的“更多”导航控制器中使用图像或以其他方式更改单元格的背景颜色?

Neither of those links are the answer to this question. 这些链接都不是这个问题的答案。 It seems Malakim is referring to the MoreViewController of the UITabBarController , and not wanting to change the tabbar colors, but the cells that makeup the MoreViewController's tableView. 似乎Malakim指的是UITabBarController MoreViewController,并且不想更改标签栏颜色,而是希望更改MoreViewController的tableView的单元格。

The answer is pretty easy. 答案很简单。 You can reference the moreViewController property of your tabBarController which would give you a reference to an instance of a UIMoreNavigationController . 您可以引用tabBarController的moreViewController属性,该属性将为您提供对UIMoreNavigationController实例的UIMoreNavigationController

UINavigationController* moreNavController = myTabController.moreViewController;

With this navigation controller you then want the root view controller's view, because this is what is holding your tableView. 然后,使用此导航控制器,您需要根视图控制器的视图,因为这就是保持tableView的原因。 In fact, the root view controller is a UITableViewController , and accessing it's view grabs the tableView directly! 实际上,根视图控制器是UITableViewController ,访问它的视图将直接获取tableView!

UITableView* moreView = ((UIViewController*)[moreNavController.viewControllers objectAtIndex:0]).view; //might need to cast here to suppress warnings //可能需要在此处强制显示以禁止显示警告

and thar ye go, moreView has a reference to hee tableView you are interested in. You could then delve further by using moreView.subviews or just make an ugly background color change like moreView.backgroundColor = [UIColor uglyColor]; 顺便说一句,moreView引用了您感兴趣的hee tableView。然后,您可以使用moreView.subviews进行深入研究,或者仅进行一个丑陋的背景颜色更改,例如moreView.backgroundColor = [UIColor uglyColor];

The method given by Steve works fine but it was giving me warning when i try to set the view of moreNavController to a table view. Steve给出的方法效果很好,但是当我尝试将moreNavController的视图设置为表视图时,它给了我警告。

warning: incompatible Objective-C types initializing 'struct UIView *', expected 'struct UITableView *'

So inorder to remove the warnings i tried the below code and it works, not sure it is the proper way 因此,为了消除警告,我尝试了下面的代码,并且它可以正常工作,不确定是否是正确的方法

UINavigationController* moreNavController = self.tabBarController.moreNavigationController;
    UIViewController* moreViewController = [moreNavController.viewControllers objectAtIndex:0]; 
    moreViewController.view.backgroundColor = [UIColor redColor];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM