並且不會有與蘋果訪問的任何問題,你不要有任何的子類只是把其他組件添加到您的工具欄:
-(UIToolbar *) toolBarActive {
if(_toolBarActive == nil) {
_toolBarActive = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 360, 320, 60)];
[_toolBarActive setBackgroundImage:[UIImage imageNamed:@"image.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
_toolBarActive.tintColor = [UIColor blackColor];
[_toolBarActive setBackgroundColor:[UIColor blackColor]];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSMutableArray *arrayItem = [[NSMutableArray alloc] init];
[arrayItem addObject:flexibleSpace];
[arrayItem addObject:self.buttonItem1];
[arrayItem addObject:flexibleSpace];
[arrayItem addObject:self.buttonItem2];
[arrayItem addObject:flexibleSpace];
[arrayItem addObject:self.buttonItem3];
[arrayItem addObject:flexibleSpace];
[arrayItem addObject:self.buttonItem4];
[arrayItem addObject:flexibleSpace];
[_toolBarActive setItems:arrayItem animated:YES];
}
return _toolBarActive;
}
其中例如buttonItem1定義爲:
- (UIBarButtonItem *) buttonItem1 {
if(_buttonItem1 == nil) {
_uttonItem1 = [[UIBarButtonItem alloc] initWithCustomView:self.button1];
[_buttonItem1 setEnabled:YES];
[_buttonItem1 setBackgroundVerticalPositionAdjustment:100.0f forBarMetrics:UIBarMetricsDefault];
}
return _buttonItem1;
}
and button1 defined as:
- (UIButton *) button1 {
if(_button1 == nil) {
_button1 = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
[_button1 addTarget:self action:@selector(addNewImage) forControlEvents:UIControlEventTouchUpInside];
[_button1 setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
}
return _button1;
}