Reputation: 77
I have a problem in making the NavigationBar
transparent instead it shows the white as background color.
I wish to achieve this
But instead i am getting the following NavigationBar
as background color.
It is showing white as background color. It is not getting transparent
Upvotes: 0
Views: 366
Reputation: 118
self.navigationController?.navigationBar.setBackgroundImage(imageWithColor(color: color.withAlphaComponent(alpha)), for: .default)
self.navigationController?.navigationBar.shadowImage = imageWithColor(color: color.withAlphaComponent(alpha))
fileprivate func imageWithColor(color : UIColor) -> UIImage? {
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
UIGraphicsBeginImageContext(rect.size)
let ctx = UIGraphicsGetCurrentContext()
ctx?.setFillColor(color.cgColor)
ctx?.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
call in func viewWillAppera
. you will get
Upvotes: 0
Reputation: 427
You also try below code.
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default);
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
self.navigationController?.navigationBar.isTranslucent = true
Upvotes: 0
Reputation: 933
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = UIColor.clear
Upvotes: 1