Apple アクセスに問題はありません。他のコンポーネントをツールバーに配置するだけで、何かをサブクラス化する必要はありません。
-(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;
}
および button1 は次のように定義します。
- (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;
}