Выполните три простых шага
1 Свойство записи:
@property (nonatomic, strong) IBOutlet UIToolbar *toolBarActive;
@property (nonatomic, strong) IBOutlet UIButton *uiButton;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *uiButtonItem;
2 Синтез:
@synthesize toolBarActive = _toolBarActive;
@synthesize uiButton = _uiButton;
@synthesize uiButtonItem = _uiButtonItem;
3 Реализация записи:
-(UIToolbar *) toolBarActive {
if( _toolBarActive == nil ) {
_toolBarActive = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 380, 320, 40)];
_toolBarActive.tintColor = [UIColor blackColor];
NSMutableArray *arrayItem = [[NSMutableArray alloc] init];
[arrayItem addObject:self.uiButtonItem];
[_toolBarActive setItems:arrayItem animated:YES];
}
return _toolBarActive;
}
- (UIButton *) uiButton {
if( _uiButton == nil ) {
_uiButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
[_uiButton addTarget:self action:@selector(deletePointFromTrip) forControlEvents:UIControlEventTouchUpInside];
[_uiButton setImage:[UIImage imageNamed:@"editable.png"] forState:UIControlStateNormal];
}
return _uiButton;
}
- (UIBarButtonItem *) uiButtonItem {
if( _uiButtonItem == nil ) {
_uiButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.uiButton];
[_uiButtonItem setEnabled:YES];
}
return _uiButtonItem;
}
Теперь, когда у вас есть uibutton на uibarbuttomitem, вы можете определить все свойства для uibutton, как, изображение, действие и т. Д.