我有一个弹出框和标题@“标题”。是否有可能在那里有 UISegmentedControl 而不是标题?换句话说,我想要一个在标题中间有一个分段控件的弹出框。如何?
popover的内容是UITableViewController,它在一个UINavigationController里面,我通过presentPopoverFromBarButtonItem:来呈现。
UIToolbar
在弹出视图顶部使用 a 。无论是在界面生成器中,还是以编程方式,在其UISegmentedControl
任一侧插入一个具有灵活空间的。例如:
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]];
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;