meaning-matters
meaning-matters

Reputation: 22986

Unable to set navigation bar color of modal view controller

I'm presenting a modal view controller like this on iPhone / iOS 8:

UIApplication*          application        = [UIApplication sharedApplication];
UIWindow*               window             = application.windows[0];
UIViewController*       rootViewController = window.rootViewController;
SomeViewController*     someViewController;
UINavigationController* navigationController;

someViewController   = [[SomeViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:someViewController];

// Set everything to black.
navigationController.navigationBar.barTintColor = [UIColor blackColor];
navigationController.navigationBar.tintColor    = [UIColor blackColor];
navigationController.navigationBar.barStyle     = UIBarStyleBlack;

navigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[rootViewController presentViewController:navigationController animated:YES completion:nil];

SomeViewController is an empty/fresh view controller that does nothing (except for also trying to set the navigation bar to black, without success).

This is in an app using a storyboard, and which has NVSlideMenuController as the window's root.

What happens is that the view controller is presented, but the navigation bar is/seems fully transparent, because when I set someViewController's background color to red, the whole screen is red (except the title). The rest of the app has a transparent navigation bar.

Another thing that might be related is that when app is going to background (with iPhone home button) and then foreground again, the view controller is no longer visible.

What am I missing or doing wrong here?

Upvotes: 0

Views: 3184

Answers (1)

Bharat
Bharat

Reputation: 3198

Try below code, may be its your Solution

#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:r/256.f green:g/256.f blue:b/256.f alpha:a]

#define ColorNav RGBACOLOR(13, 127, 161, 1.0)

self.navigationController.navigationBar.barTintColor = ColorNav;
self.navigationController.navigationBar.translucent  = FALSE;

Upvotes: 5

Related Questions