我有一个 UIToolbar,上面有 UIBarButtonItems。我想给它添加分段控制。
//Add UIToolbar
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 425, 320, 35)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[self.view addSubview:toolbar];
//Add Gallery Button
UIButton *galleryButton = [UIButton buttonWithType:UIButtonTypeCustom];
[galleryButton addTarget:self action:@selector(ScrollView:) forControlEvents:UIControlEventTouchUpInside];
galleryButton.frame = CGRectMake(0, 0, 25, 25);
UIImage *ime = [UIImage imageNamed:@"_gallery.png"];
[galleryButton setImage:ime forState:UIControlStateNormal];
UIBarButtonItem *gallerybutton = [[UIBarButtonItem alloc] initWithCustomView:galleryButton];
//Add play/Pause button
_playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_playButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
_playButton.frame = CGRectMake(0, 0, 25, 25);
[_playButton setImage:[UIImage imageNamed:@"1play.png"] forState:UIControlStateNormal];
[_playButton setImage:[UIImage imageNamed:@"audiopause.png"] forState:UIControlStateSelected];
UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithCustomView:self.playButton];
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
//Add buttons to the array
NSArray *toolbarItems = [NSArray arrayWithObjects: play, flexItem, gallerybutton, nil];
[toolbar setItems:toolbarItems];
有没有办法将分段控件添加到 UIToolbar 上现有的 uibarbuttonitems。