Skip to content

Instantly share code, notes, and snippets.

@Denismih
Created May 30, 2019 07:09
Show Gist options
  • Save Denismih/8876e67b980271adadb85738467ba9fe to your computer and use it in GitHub Desktop.
Save Denismih/8876e67b980271adadb85738467ba9fe to your computer and use it in GitHub Desktop.
func setNavigationBar() {
let screenSize: CGRect = UIScreen.main.bounds
let navBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: screenSize.width, height: 44))
let navItem = UINavigationItem(title: "")
let doneItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.done, target: nil, action: #selector(done))
navItem.rightBarButtonItem = doneItem
navBar.setItems([navItem], animated: false)
self.view.addSubview(navBar)
}
@objc func done() { // remove @objc for Swift 3
self.dismiss(animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment