0

I have a code in the AppDelegate.m that sets all UINavigationBar hex colors to #125687

Code from the AppDelegate.m

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]



@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    [[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x125687)];

Here's the issue: I put two UINavigationBars on top of each other in the viewcontroller so the UINavigationBar goes under the status bar. The navigation bar under the status bar is below the main navigatonbar. The second navigation bar has a different color from the main one.

Here's what it looks like:

enter image description here

(The second navigation bar is the navigation bar that has a lighter color that the bar with the title "Community")

Question: How can I fix it so both UINavigationBars have the same hex color (#125687)?

PHP Web Dev 101
  • 515
  • 1
  • 7
  • 20
  • http://www.appcoda.com/customize-navigation-status-bar-ios-7/ – Adrian Sep 15 '15 at 01:30
  • my question is why use two navigation bar when you can use 64px navigation bar which directly goes below your status bar? – Ganesh Somani Sep 15 '15 at 01:33
  • @GaneshSomani is there anyway to alter the height of the navigation bar – PHP Web Dev 101 Sep 15 '15 at 01:34
  • I think the problem with different color is that the navigation bar has some alpha value. Hence the color overlapping is taking place. Did you happen to come across this question http://stackoverflow.com/questions/19105766/ios-7-status-bar-collides-with-navigationbar – Ganesh Somani Sep 15 '15 at 01:39
  • Also what happens if you remove the navigation bar which goes below the status bar? – Ganesh Somani Sep 15 '15 at 01:40
  • The alpha values are the same on both. And if I take out the one below, it looks like this - http://i.stack.imgur.com/GheqW.png – PHP Web Dev 101 Sep 15 '15 at 01:54

2 Answers2

1

Do not use two Navigation Bar.

You can simply extend you navigation bar. Either you can embed your UIViewController into a UINavigationController

Or

For extending your single navigation bar below the status bar you can use the following

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
   return UIBarPositionTopAttached;
}

Refer this answer

Community
  • 1
  • 1
Ganesh Somani
  • 1,848
  • 1
  • 24
  • 36
-1

Conor of UIStatusBargets automatically set to match the colour of UINavigationBar with:

self.navigationController.navigationBar.barTintColor

Please try setting this to your desired colour.

EDIT:

Instead of 2 navigation bars, can you please try this

UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, 320, 22)];
statusBarView.backgroundColor = [UIColor yellowColor]; // Replace this with your color
[self.navigationController.navigationBar addSubview:statusBarView];
Abhinav
  • 36,284
  • 39
  • 178
  • 301
  • What file does it go in? – PHP Web Dev 101 Sep 15 '15 at 02:05
  • In my case I have created a subclass of `UINavigationController` and have implemented it there. All my view controller uses my custom navigation controller class. Of course I did that to have more such common functionalities written once. You can put it in `AppDelegate`. – Abhinav Sep 15 '15 at 02:08
  • I got the error - "Property 'navigationController' not found on object of type 'AppDelegate*' – PHP Web Dev 101 Sep 15 '15 at 02:10
  • BTW... what is the iOS version you are running your application on? – Abhinav Sep 15 '15 at 02:14
  • When I run the app on my phone, it is 8.4 (latest version) But the target is set to 7.0 – PHP Web Dev 101 Sep 15 '15 at 02:18
  • I don't think you need 2 navigation bars here. Any reason doing it that way? You need to setup your first one correctly so status bar do not overlap with it. Here is the apple documentation link for the same: https://developer.apple.com/library/ios/qa/qa1797/_index.html – Abhinav Sep 15 '15 at 02:42
  • Let me explain a little better - I have one navigation bar that I am using as a background for the status bar. The second navigation bar on the bottom is for the title bar. – PHP Web Dev 101 Sep 15 '15 at 02:45
  • But why so? Why are you adding a navigation bar as background for status bar? Thats not typical suggested way. – Abhinav Sep 15 '15 at 02:51
  • Because then the status bar color is transparent and there is no background color – PHP Web Dev 101 Sep 15 '15 at 02:52
  • Is there any way to make a specific background color for the status bar – PHP Web Dev 101 Sep 15 '15 at 02:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/89633/discussion-between-abhinav-and-php-web-dev-101). – Abhinav Sep 15 '15 at 03:26