Skip to content

Instantly share code, notes, and snippets.

@jaminguy
Created April 7, 2015 02:26
Show Gist options
  • Save jaminguy/868a4a3be6a1b5f8c5f1 to your computer and use it in GitHub Desktop.
Save jaminguy/868a4a3be6a1b5f8c5f1 to your computer and use it in GitHub Desktop.
UISegmentedControl in UINavigationBar
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let segmentedControl = UISegmentedControl(items: ["Less Filling", "Tastes Great"])
segmentedControl.addTarget(self, action: "segmentChanged:", forControlEvents: UIControlEvents.ValueChanged)
segmentedControl.selectedSegmentIndex = 0
self.navigationItem.titleView = segmentedControl
}
func segmentChanged(sender: UISegmentedControl) {
println("\(sender.selectedSegmentIndex)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment