I\'m adding a UISegmentedControl
to the Navigation bar programatically where the titleView
should be. But as Apple docs have mentioned under titl
Try this
Remove this line --- > self.navigationItem.leftBarButtonItem = nil;
Add this instead
UISegmentedControl *statFilter = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Filter_Personnal", @"Filter_Department", @"Filter_Company", nil]];
[statFilter setSegmentedControlStyle:UISegmentedControlStyleBar];
[statFilter sizeToFit];
self.navigationItem.titleView = statFilter;
Only change is I have added this line :
[statFilter sizeToFit];
Hope this Helps !!!
You can create a UIBarButtonItem
with a custom view which could potentially be your UISegmentedControl
.
Something along the lines of the following may work.
//create segmented control with items
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"One", @"Two", nil]];
//create bar button item with segmented control as custom view
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
//add segmented control bar button item to navigation bar
[[[self navigationController] navigationItem] setRightBarButtonItem:barButtonItem];
I haven't tested this but it should be along the right lines of what you need.