In my first page, the navigation bar should be transparent, and when push to next page, the navigation bar should be a image. I worked it out by changing the _UIBarBackground or _UINavigationBarBackground's alpha.
But I meet a big problem, in the first page, view should be placed and draw from (0,0) so I set the navigation bar's isTranslucent to true, that all works fine. But when I enter the next page, background image shows with a translucent looking which I don't want.
btw, I set background using:
navVC.navigationBar.setBackgroundImage(UIImage(named: "navigation_bar_background"),
for: .default)
I checked the image used here, and it's not translucent.
What can I do with this issue? I don't want set viewController's extendedLayoutIncludesOpaqueBars to true due to ugly appearance when animation.
Combination of these 2 solutions will help.
http://ioscodeguide.blogspot.in/2014/01/navigation-bar-bagground-image.html
http://ioscodeguide.blogspot.in/2014/01/navigation-bar-font-style-and-font.html
In first view:
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
In 2nd view:
Set image to your navigationBar using the following link.
How to set Navigation Bar Bagground image - By - iOSCodeGUIDE
Adding to that
To keep navigation bar transparent in first page and display on 2nd page,
1st Page viewwill appear Hide-Yes NavigationBarHide, and on view did disappear Hide-No
Related
I am trying to achieve a transparent navigation bar such that the background image is shown clearly. Currently i have used a base controller class where i have put a code for transparent navigation bar:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear
But currently i am getting the clear navigation bar only on first page. If i push and go to the second controller i can see a empty white space.
See the below images:
First page with cleared navigation bar
Second page with empty white space at the top
Why the navigation bar is not getting transparent? Any ideas?
As Your navigation bar is transparent, it will show your viewcontroller's view background color.
I think, your second page view controller's view background color is White. Thats the reason you are getting white color.
Add Top Constraint to SuperView, Not to TopLayout Guide
change the view background
self.navigationController?.navigationBar.isTranslucent = true
For more detail about isTranslucent read this doc
https://developer.apple.com/documentation/uikit/uinavigationbar/1624928-translucent
I am trying to set color to navigation bar for different controllers but same color showing different effect.
Add following line to your viewDidLoad:method of navigationController class,
self.navigationBar.translucent = NO;
Visit navigationBar translucent property.
I'm having problems trying to figure out how to change the color of the buttons on the navigation controller.
Previously I had used the following:
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:226/255.0 green:66/255.0 blue:66/255.0 alpha:0.0]];
and this worked, but I added a new view with a toolbar, and the tool bar button images will not show. If I remove the global coloring, the tool bar items show just fine.
I've tried setting the tint color on both the leftBarButtonItem and the backBarButtonItem in the viewDidLoad method of the view, but both of those properties appear to be null.
I don't want to change the color of the entire navigation bar, just the buttons. Is there a way to do this?
Yeah, I'll just post this as an answer. Your alpha is set to 0. So you're basically saying the same thing as [UIColor clearColor].
Not sure how that ever worked to give you a tint color on your bar button items.
In swift, it can be accomplished by the following command:
if let navController = self.navigationController
{
navController.navigationBar.tintColor = UIColor.whiteColor()
}
The tabbar in first view is what I want. Because the second view isn't a scrollview, so I can't extend it to bottom by using self.edgesForExtendedLayout = UIRectEdge.Bottom.
It looks unacceptable.
And I don't want to set Translucent of uitabbar to false, it's not fancy.
I try in another way:
[[UITabBar appearance] setBarTintColor: [UIColor whiteColor]];
It doesn't work. To make it looks more clear, I change the color to red. And the last tabbar also looks like covering some black views.
Consider of the tabbar is translucent, what's the view under the UITabbar view?
This is the final answer of why it doesn't work when changing the tintcolor of bar. Because the view under UITabbar view is black.
Thanks to the Xcode awesome debugging function. We could locate the view under UITabbar view easily.
It's UIWindow. So the solution is to simply change the window's backgroundColor to white.
I would say that adding this code in viewDidLoad of your viewController will solve your issue:
edgesForExtendedLayout = .all
extendedLayoutIncludesOpaqueBars = true
Plus you can keed your tabBar translucent and not set any background color.
i´m developing an iOS-Application with VisualStudio/Xamarin. I have to set the transparency on the navigationbar to 100%. But let me explain the whole thing:
On the first view the navigationbar have a background image set by this code:
var navigationImage = UIImage.FromFile("gradient.jpg");
UINavigationBar.Appearance.SetBackgroundImage(navigationImage, UIBarMetrics.Default);
The first view got several tablecell items, if clicked, a detail view shows up.
On that detail view the navigationbar should be completely transparent! Only the back button and a title should be leftover.
I tried everything from translucent = yes to this solution which i also found here on stackoverflow.
I also tried to set a color to the first navigationbar and then change it on the next view to another color which works, but if i get back to the firstview the navigationbar color stays the same, even if i override the ViewWillAppear-method from the first view where the BarTintColor is set.
Thanks for your help!
greetings
Well, for what it's worth, I actually followed your solution link and translated it to Xamarin. If I put the following code in ViewDidLoad on my VC, the Navigation Bar is completely transparant ;)
this.NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.Default);
this.NavigationController.View.BackgroundColor = UIColor.Clear;
this.NavigationController.NavigationBar.BackgroundColor = UIColor.Clear;
this.NavigationController.NavigationBar.ShadowImage = new UIImage ();