iOS double navigation bar by set translucent OFF - ios

at First:
I work with the storyboard interface builder...
I tried to color my navigation bar like Instagram:
UIColor *mainColorBlue = [UIColor colorWithRed:0.071 green:0.337 blue:0.533 alpha:1];
[[UINavigationBar appearance] setBarTintColor:mainColorBlue];
[[UINavigationBar appearance] setBackgroundColor:mainColorBlue];
But if i set the color to mainColorBlue, it is not this color. I've read in the internet, that it is cause from translucent. So I set translucent to OFF.
But now, my Problem is: If i deactivate the translucent and activate opaque and start the app on my external device, under the navigation bar is another navigation bar. If i switch the translucent to ON again,the second navigation bar isn't shown.
What i have to do, that the second navigation bar disappear?

I resolve the problem.
I added a subview on position 0,0 to color the statusbar.
UIView *statusBarColor = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];
statusBarColor.backgroundColor = mainColorBlue;
[self.view addSubview:statusBarColor];
So this View is displayed under the navigation bar. I removed this code and now it works.

Related

Navigation bar color not setting properly

Why is the navigation bar color coming so weired? Why is it white above and only a bit red at the bottom. I cannot make out if the status bar is overlapping my navigation bar or what. This is the code I used to change the color of the navigation bar background:
[navbar setBackgroundColor:[UIColor redColor]];
Solution
[navbar setBarTintColor:[UIColor redColor]];
[navbar setTranslucent:NO];
Why
The color of a UINavigationBar is set with its barTintColor property.
What you're seeing is the translucent white navigation bar above your red background. The bit at the bottom is where UINavigationBar renders a shadow below the bar view.
I think this image is sufficient to solve your problem.

ios - Set Status Bar Background color

Apps like Facebook, Instagram and YikYak seem to have a navigation bar that's coloured, and when its swiped, it hides however, the status bar is still there with a background colour thats the same as the navigation bar?
Example:
Facebook Navigation Bar Shown
Then user swipes up (on a tableview or something) then the navigation bar hides but the status bar is still there with a coloured background.
How can I implement this?
I have achieved a coloured Navigation bar with a white status bar that hides on swipe with this code:
// Set Navigation Bar Color
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:(252/255.0) green:(103/255.0) blue:(105/255.0) alpha:1.0]];
// Set Status Bar Style
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Now I just need to figure out how to change the status bar's background colour.
I have gotten close with the following code (that I add to my app delegate didFinishLaunchingWithOptions) that adds a coloured view, however it adds the view to the very top of my view controller hierarchy, where as I just want to add the view to my table view controller.
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
view.backgroundColor=[UIColor colorWithRed:(252/255.0) green:(103/255.0) blue:(105/255.0) alpha:1.0];
[self.window.rootViewController.view addSubview:view];
Does anyone know how to ether add this view to just one of my view controllers, or a better way to do this?

How to deal with default paddings while customise navigation bar with title view?

I am trying to customise the navigation bar with title view.
But it seems setting title view comes with its own left and right and top paddings.I was expecting the title view to cover the whole navigation bar according to the frames given.
Is it expected behaviour and if YES than how to deal with that?
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 44)];
view.backgroundColor = [UIColor greenColor];
//Navigation Bar
self.navigationItem.titleView = view;
If you just want the navigation bar to be green use [self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]]; in iOS 7+ or [self.navigationController.navigationBar setTintColor:[UIColor greenColor]]; in iOS 6-
Yes, it seems it is not possible to remove that left/right padding. This is the screenshot form debugging views in Xcode after running your code
The outside view that is gray is the navigationBar and the green is obviously the titleView. No matter the frame for the titleView, it is clipped.
Apple documentation says just this:
Custom title views are centered on the navigation bar and may be resized to fit.
I think the only solution would be to subclass the navigationBar, so that you override the titleView frame.

Changing the colour of Navigation Controller bottom toolBar

I am trying to change the colour of the bottom bar of my Navigation Controller. I have managed to change the top NavBar in my appdelegate by adding
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.688 green:0.437 blue:0.794 alpha:1.0]];
I want to apply this to the bottom bar also.
You can use [UIToolbar appearance] to set the appearance of UIToolbar
Good luck
I had the same problem, but could escape this by setting a tag for my navigationBar in my storyboard. Then I could change the navigationBar's color like this:
let navigationBar = (self.view.viewWithTag(someNumber) as UINavigationBar)
navigationBar.barTintColor = UIColor.blackColor()
This is not ideal unless you can guarantee that the number of subviews in your view is less than "someNumber". If you can though, then this should work.

Navigation Bar color and a View's color

I'm getting a weird, i have a navigation bar and a view that is right under it.
I set both of them to [UIColor BlueColor], but at run time the outcome is that the nav bar has a slit darker color then the view.
Any knows what causes this?
Thanks
Your problem is that the navigation bar is translucent, and therefore the bar color is put on top of the view's color, making it appear darker. Try making the bar not translucent.
navigationBar.translucent = NO;
You can try this one:--
navigationController.navigationBar.barTintColor = [UIColor greenColor];
or
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];

Resources