How do I add UISegmentedControl
in UINavigationItem
?
I want to create a UINavigationBar
with segment control which add in title of navigat
You're almost there, you just need to add the segmented control to a UINavigationItem and add that to your UINavigationBar:
// This code is used for a custom navigation bar
UINavigationItem* newItem = [[UINavigationItem alloc] initWithTitle:@""];
[newItem setTitleView:segmentedControl];
// Assuming you already have a navigation bar called "navigationBar"
[navigationBar setItems:[NSArray arrayWithObject:newItem] animated:NO];
// No memory leaks please...
[newItem release];
or if you want to use an existing controller
// This is used for an existing navigation controller
[navigationController.navigationBar.topItem setTitleView:segmentedControl];
// or if you want to access through the root view controller of the nav controller
[rootController.navigationItem setTitleView:segmentedControl];
That should set the center view of your navigation bar to the segmented control.
Hope I could help!
EDIT: If you need more help, the Apple documentation of these classes is quite thorough:
UINavigationItem
UINavigationBar