Search code examples
iphoneiosuicoloruimodalpresentationstyle

How to make navigation bar black in modal view in ios


I made a modal view. I don't want default color. How can I put its navigation to black color?

Here is my code which doesn't work:

EditBillItemModalViewController *editBillItemvc = [[EditBillItemModalViewController alloc] init];
editBillItemvc.anItem = anItem;
editBillItemvc.navigationController.navigationBar = [UIColor blackColor];
editBillItemvc.onOKButtonClickedCallBack = ^(Item item){ [aBill.listOfOrderedItem replaceObjectAtIndex:bvc.selectedItemIndex withObject:item]; [(UITableView)bvc.view reloadData]; [self setnewTotalAfterEditBillItem]; }; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:editBillItemvc]; 
[self presentModalViewController:navController animated:YES];

Solution

  • Assuming it has a UINavigationController you can do:

    modalView.navigationController.navigationBar.tintColor = [UIColor blackColor];

    EDIT after code added:

    From your code it looks like here is your succession of events:

    1. Instantiate view controller
    2. Set bar tintColor to black
    3. Instantiate nav controller
    4. Present nav controller as modal view

    Obviously this isn't going to work as you're changing the tint color before you're instantiating the nav controller.

    Thus, you need to either move step 2 to between 3 and 4 or, even easier after this line:

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:editBillItemvc];
    

    Just put:

    navController.navigationBar.tintColor = [UIColor blackColor];