How do I add UISegmentedControl
in UINavigationItem
?
I want to create a UINavigationBar
with segment control which add in title of navigation bar.
UISegmentedControl
has two indexes.
Here's what I have:
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:[UIImage imageNamed:@"grid.png"],[UIImage imageNamed:@"list.png"],nil]];
[segmentedControl addTarget:self action:@selector(segmentedAction) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, 40);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
[segmentedControl setTintColor:[UIColor clearColor]];
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.rightBarButtonItem = segmentBarItem;
I had put it in right side. So, also want to put in middle of navigation bar.
This does not work please let me know if I did anything wrong.
Thanks