I have an app with a UITabBarController that has more than five tabs.
When I press the More tab, I go to the moreNavigationController which is a UINavigationController .
As you can see, I have figured out how to style the Title , Tint , Table color , and the Edit button on the More screen, as well as the Configure screen from pressing the Edit button.
What I have not been able to figure out is how to style the back button, titled More , when I select an item in the table.
Each tab has it's own class, GRWTabSettingsViewController for example, which inherits from GRWViewController , which provides common functionality for all tabs, which then inherits from UIViewController .
When on the Settings screen (or any other tab), I am trying to edit the More back button.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[(UIBarButtonItem *)[(UINavigationItem *)[(UINavigationBar *)[(UINavigationController *)[self navigationController] navigationBar] topItem] leftBarButtonItem] setTintColor:[UIColor darkGrayColor]];
[self.navigationController.navigationBar.topItem.leftBarButtonItem setTintColor:[UIColor darkGrayColor]];
}
However, this navigationController is clearly the parent since these changes get applied to the More screen and not the Settings screen.
What am I misunderstanding and how would I modify the buttons displayed on the navigation bar of the screen I am viewing?
=== SOLUTION ===
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// use backBarButtonItem not leftBarButtonItem
//[(UIBarButtonItem *)[(UINavigationItem *)[(UINavigationBar *)[(UINavigationController *)[self navigationController] navigationBar] topItem] leftBarButtonItem] setTintColor:[UIColor darkGrayColor]];
//[self.navigationController.navigationBar.topItem.leftBarButtonItem setTintColor:[UIColor darkGrayColor]];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:self.navigationController.navigationBar.topItem.title
style:UIBarButtonItemStylePlain
target:nil
action:nil];
[backButton setTintColor:[UIColor darkGrayColor]];
self.navigationController.navigationBar.topItem.backBarButtonItem = backButton;
// these do not work
//[self.navigationController.navigationBar.topItem.backBarButtonItem setTintColor:[UIColor darkGrayColor]];
//[backButton setTintColor:[UIColor darkGrayColor]];
}
Did take me a while to figure out that I can not format the button through self , or format the button after the assignment to self .
你应该定制backBarButtonItem
以前的导航项目的,不是的topItem
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.