Change the background color of "More" view controller
Is it possible to use an image or otherwise change the background color of cells in the "More" navigation c开发者_运维知识库ontroller of a 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.
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
.
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. In fact, the root view controller is a UITableViewController
, and accessing it's view grabs the tableView directly!
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];
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.
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];
精彩评论