iOS navigation bar bottom line is missing - ios

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.

Related

Xcode transparent navigation bar background

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

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

UINavigationBar Transition

Currently, I am having an issue with the transition of two navigation bars. The root view has a transparent navigation bar, while the other navigation bar is opaque with a bar tint color. This is what is currently going on:
https://youtu.be/xfpNnjfOMRc. As you can see, the transparent navbar blinks. The transparent nav bar has this line of code: self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default).
To go about solving this issue, I added this block of code to the second view controller (with the bar tint color):
override func willMoveToParentViewController(parent: UIViewController?) {
super.willMoveToParentViewController(parent)
if parent == nil {
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
}
}
Now however, this happens: https://youtu.be/oMLL0v9_9Yc. When the back button is pressed, the nav bar of the second view controller is rendered transparent, solving the issue above. However, this is not the ideal solution. I simply want a smooth transition between the two nav bars. Ideas?

Can't set fully transparent navigation controller on top of tableView

I do know how to make transparent controller:
self.navigationController!.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController!.navigationBar.shadowImage = UIImage()
self.navigationController!.navigationBar.translucent = true
and it works if in storyboard, in selected ViewController I set Adjust Scroll View Insets + Under Top Bar, but then part first row loads of screen. If I disable those two options, First row seems to be in place, but then Navigation Controller is all black.
Any suggestions how to fix it?
You should just be able to hide the Navigation bar for the Navigation Controller.
In the view controller that you want to hide from:
[self.navigationController setNavigationBarHidden:YES animated:YES]

Resources