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.

Answers


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, e.g. 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];
}

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.


Need Your Help

How to read excel(.xlsx) in java using poi?

java apache-poi

I am trying to read excel in java.I have following code.

How do I make PIL take into account the shortest side when creating a thumbnail?

python image math python-imaging-library resize

Currently, for my function below...the image will be resized based on the longest side.

inet_aton() returning success for invalid ip addresses?

c++ c linux gcc ip

I am looking for some function to verify that if given string is a valid ipv4 address,

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.