UIPopover: UISegmentedControl instead of title
Question
I have a Popover and the title @"Title". Is it possible to have UISegmentedControl there, instead of the title? In other words, I want a popover which has a segmentedcontrol in the middle of header. How to?
The content of popover is UITableViewController, it is inside a UINavigationController, and I present it via presentPopoverFromBarButtonItem:.
Solution 2
UISegmentedControl *sc = [[[UISegmentedControl alloc] initWithItems:nil] autorelease];
// config the control
UIBarButtonItem *scItem = [[[UIBarButtonItem alloc] initWithCustomView:sc] autorelease];
// add the segmented control, instead of the UILabel title
self.navigationItem.titleView = scItem.customView;
OTHER TIPS
Use a UIToolbar
at the top of the popover view. Either in interface builder, or programatically, insert a UISegmentedControl
with flexible space either side of it. For example:
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems
[NSArray arrayWithObjects:@"Segment 1", @"Segment 2", nil]];
UIBarButtonItem *segmentedBarButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[self.toolbar setItems:[NSArray arrayWithObjects:flexibleSpace, segmentedBarButton, flexibleSpace]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow