On the picture on the right is what I need and on the left is what I get:
1
I'm trying to make a transparent navigation bar, and in the book which I'm reading it's written that all you need to do is to insert this code in viewDidLoad() method of the preferable View Controller:
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.tintColor = .white
tableView.contentInsetAdjustmentBehavior = .never
But all I get is a white navigation bar. Also if's written that the difference of bars on the picture is in this code:
tableView.contentInsetAdjustmentBehavior = .never
But it doesn't work for me
I downloaded the final project of this book's chapter and everything works fine there, though I've tried to copy-paste the code and still got nothing changed
And the thing is - I've already tried to insert this code:
navigationController?.navigationBar.isTranslucent = true
But it doesn't work
If it matters, the book is "Beginning iOS 11 programming" by AppCoda
You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ). Set isTranslucent to true .
Creating a transparent navbar is very easy - just don't add a color class . bg-* to the navbar. In this case, the Navbar will take the color of the parent's background color.
Use following code:
navigationController?.navigationBar.isTranslucent = true
Hope it will help you.
Edit (UPDATE)
Use Below Code:
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = false
UPDATE 2
override func viewDidAppear(_ animated: Bool) {
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.tintColor = .red
}
It have to be work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With