Skip to content

Instantly share code, notes, and snippets.

@agibson73
Created December 4, 2016 20:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agibson73/87a44defc2f8e9088aa2970fecd7e8e9 to your computer and use it in GitHub Desktop.
Save agibson73/87a44defc2f8e9088aa2970fecd7e8e9 to your computer and use it in GitHub Desktop.
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