Xcode transparent navigation bar background - ios

I'm using a custom navigation bar in a view, and I want the bar not to be visible (except for the text and the buttons of course). the view is white, therefore the background of the bar needs to be also white or transparent. but no matter, what I try, it is always barely visible:
This is what it looks like(I know you have to look hard, but the bottom line is visible):
if I need to write any code, please use swift

Try this :
self.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.isTranslucent = true

Related

Separate colors for viewcontroller background and statusbar background

I want a blue color for my navigation bar and status bar backgrounds while a white color background for the rest of the view controller. I want this for all my view controllers in the app. Naturally, I have in my BaseViewContrller for statusbar:
self.view.backgroundColor = UIColor.blue
But this causes the whole view controller to go blue. Is adding a white UIView and constraining it to safe areas the only option or there is an easy way to accomplish this?
Yes, because you're setting ViewController's view background color and not navigationBar background color. Instead set background color of navigation bar
navigationController?.navigationBar.backgroundColor = .blue

Navigation Bar and Status Bar colors/ invisible iOS

I'm trying to realize navigation bar and status bar that take colors of the image on top of controller. I've try with this two code:
self.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationBar.shadowImage = UIImage()
but it change only the main controller and I need to make invisible only the second controller not the main. Here is an image of what I want exactly.
If you want the color of the image just put the image on top and later a visual effect view.
You can make the navigation bar transparent with this extension by calling:
navigationController?.navigationBar.apply(.transparentWhite)
in the viewWillAppear of any view controller in which you want this behaviour.
If you want other themes, define them as I defined the one in the gist:
static var transparentWhite: NavigationTheme { return NavigationTheme(attributes: [.font: UIFont(name: .avenirNextRegular, size:14.0)], barColor: .clear, tintColor: .white) }`

UINavigation bar not getting cleared in swift3 Xcode

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

when navigationBar.isTranslucent is true, the backgroundImage of navigationbar become translucent too

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

iOS navigation bar bottom line is missing

I makes the navigation bar completely transparent by adding the following codes in viewWillAppear:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
self.navigationController?.navigationBar.barStyle = UIBarStyle.Black
Before the current view disappear, I reset the navigation bar by doing this in the viewDidDisappear method:
self.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = nil
but it turns out the little bottom line of the navigation bar is missing, here is the image that shows the normal navigation bar:
but it turns out being like this:
any idea about what is going on? and any solutions?
thanks
it's missing because you set shadow image to nil. To fix this, delete line below :
self.navigationController?.navigationBar.shadowImage = nil
The navigation bar shadow is only visible when the content scroll view is scrolled a certain distance vertically.
The "content scroll view" is the key—it's the first subview in the controller's view. Starting with iOS 15 you can set it but otherwise, it's based on the order of subviews.
This is also the way that the navigation bar determines whether to display a large title below the navigation bar when large title is enabled.
Frustratingly, not only is this concept not documented by Apple, even the new methods they added this year provide no description or any text at all.

Resources