简体   繁体   中英

UIMoreListController edit modalViewController toolbar (or navigation bar) color change

here is my problem. I have an application that uses a UITabBar, and, on some Views some NavigationControllers, and the bars are all Black Opaque. As I have more than 6 tabs, it opens the UIMoreListController, so far so good, I can change the color of the Navigation bar there. My problem is when user clicks on Edit button to organize the toolbar on the moreListController. The title bar (which I do not know if it is a toolbar or a navigationBar) is blue. I would like to change it to black opaque. anyone knows how to do it?? Best regards! Marcelo Marsson.

There is a much easier way to change all the navigation bar styles instead of changing each one separately or setting delegates for the tabbar or anything else:

[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack]; 

Just set this code in one of your initial views. With this, your more navigation controller and the configuration navigation controller (that appears after clicking "Edit" in more navigation controller) get a different style. Like this you can change its color to a different one or change the background image.

Hope this helps.

I did this in a previous project (however, I must stress the app was never released) by implementing the UITabBarControllerDelegate protocol, and this method in particular:

- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers
{
    UIView *editView = [[[self.tabBarController view] subviews] objectAtIndex:1];
    UINavigationBar *modalNavBar = [[editView subviews] objectAtIndex:0];
    [modalNavBar setBarStyle:UIBarStyleBlack];
}

Of course, this is extremely prone to breaking, because I'm assuming that the items in the subviews array at those indexes are what I expect them to be.

If you're going to try this method, I would proceed with caution and do as many checks as you can before going ahead, eg check the bounds of the array before accessing certain indexes - check if the objects at those indexes respond to the method you're about to send to them, and so on.

Again, I don't think I could recommend this approach for a shipping app, but I don't know of any other way to do this prior to iOS 5 with it's UI customisation APIs.

First answer works perfect, but I wanted some checkings... This way, the worst thing that can happen (besides apple not approving the app) is that the bar won't change color. Thanks Jasarien for the guidance!

    - (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers
{
  //Prepara a variavel que vai armazenar a view;
    UIView* edtView=nil;


    for (int i=0; i<[[[self.tabBarController view] subviews]count]; i++) {
        //checa se a subview é da classe esperada...
        if ([NSStringFromClass( [[[[self.tabBarController view] subviews] objectAtIndex:i]class]) isEqualToString:@"UITabBarCustomizeView"])
        {
            //Beleza... quebra o laço...
            NSLog(@"Achei!! sou eu do Indice %d",i);
            edtView=[[[self.tabBarController view] subviews] objectAtIndex:i];
            break;
        }
    }
    //Se nao achar a variavel, sabe-se lá deus por que, sai do método.
    if (edtView==nil) {
        return;
    }

    //Pega a NavigationBar
    UINavigationBar *modalNavBar = nil;

    for (int i=0; i<[[edtView subviews]count]; i++) {
        //checa se a subview é da classe esperada...
        if ([[[edtView subviews]objectAtIndex:i]isKindOfClass:[UINavigationBar class]])
        {
            //Beleza... quebra o laço...
            NSLog(@"Achei!! sou eu do Indice %d",i);
            modalNavBar=[[edtView subviews]objectAtIndex:i];
            break;
        }

    }
    //checa se a navBar existe
    if (modalNavBar==nil) {
        return;
    }
//muda a cor da navBar!!!
[modalNavBar setBarStyle:UIBarStyleBlack];
}

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.

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