0
votes

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)?

2
my question is why use two navigation bar when you can use 64px navigation bar which directly goes below your status bar?Ganesh Somani
@GaneshSomani is there anyway to alter the height of the navigation barPHP Web Dev 101
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 stackoverflow.com/questions/19105766/…Ganesh Somani
Also what happens if you remove the navigation bar which goes below the status bar?Ganesh Somani

2 Answers

1
votes

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

-1
votes

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];