Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Transparent Navbar
call in viewDidLoad
setUpNavBar(bottomBorderColor: .white, opacity: 0.4, height: 1)
func setUpNavBar(bottomBorderColor:UIColor,opacity:Float,height:CGFloat){
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
let navLabel = UILabel(frame: CGRect.zero)
navLabel.backgroundColor = UIColor.clear
navLabel.font = UIFont.systemFont(ofSize: 18)
navLabel.textAlignment = NSTextAlignment.center
navLabel.textColor = UIColor.white
navLabel.text = "Tranparent Navbar"
navLabel.sizeToFit()
self.navigationItem.titleView = navLabel
let navBottomBorder = UIView(frame: CGRect(x: 0, y: self.navigationController!.navigationBar.frame.size.height - 1, width: self.view.frame.size.width, height: height))
navBottomBorder.backgroundColor = bottomBorderColor
navBottomBorder.layer.opacity = opacity
navBottomBorder.isOpaque = true
navigationController?.navigationBar.addSubview(navBottomBorder)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment