Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IB to add a UISegmentedControl to a NavigationBar

I'm current creating a UISegmentedControl programmatically in a view controller's viewDidLoad method and adding it to the view controller's navigation bar by assigning it to self.navigationItem.titleView.

That's easy enough, but I'd like to be able to do this in Interface Builder as well and so far haven't been able to figure out how. Google hasn't been much help either. Can someone describe how to do this in IB or point to an online example? I'd be much appreciative. Thanks, Howard

like image 461
hkatz Avatar asked Dec 10 '25 15:12

hkatz


1 Answers

If you've got whole nav stack in the nib, it's actually pretty easy; you can just drag it into the title area and IB does the right thing automatically.

Otherwise, you can just add the segmented control to the nib (not necessarily a subview) and then add an @property IBOutlet to it from your view controller. Then in viewDidLoad, assign it to the titleView as normal. Remember to release in dealloc, and you're golden.

like image 151
Andrew Pouliot Avatar answered Dec 12 '25 07:12

Andrew Pouliot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!