Skip to content

Instantly share code, notes, and snippets.

@KOWLOR
Last active August 29, 2015 14:18
Show Gist options
  • Save KOWLOR/3391740c5de4f4d3cd4e to your computer and use it in GitHub Desktop.
Save KOWLOR/3391740c5de4f4d3cd4e to your computer and use it in GitHub Desktop.
import UIKit
class TodosViewController: UIViewController, UINavigationBarDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(animated: Bool) {
// Create the navigation bar
let navigationBar = UINavigationBar(frame: CGRectMake(0, 20, self.view.frame.size.width, 44)) // Offset by 20 pixels vertically to take the status bar into account
navigationBar.backgroundColor = UIColor.whiteColor()
navigationBar.delegate = self;
// Create a navigation item with a title
let navigationItem = UINavigationItem()
navigationItem.title = "Title"
// Create left and right button for navigation item
let leftButton = UIBarButtonItem(title: "Left", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
let rightButton = UIBarButtonItem(title: "Right", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
// Create two buttons for the navigation item
navigationItem.leftBarButtonItem = leftButton
navigationItem.rightBarButtonItem = rightButton
// Assign the navigation item to the navigation bar
navigationBar.items = [navigationItem]
// Make the navigation bar a subview of the current view controller
self.view.addSubview(navigationBar)
}
func positionForBar(bar: UIBarPositioning!) -> UIBarPosition {
return UIBarPosition.TopAttached
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment