Чтобы изменить размер кнопки навигационной панели - или настроить ее любым способом - вам нужно создать пользовательский UIBarButtonItem
для добавления на навигационную панель.
Следующий фрагмент кода создаст настроенный UIBarButtonItem
, который содержит настраиваемую кнопку с обычными и выделенными изображениями и имеет размер, соответствующий размеру изображения:
UIButton *customButton = nil;
UIImage *buttonImage = nil;
UIImage *pressedButtonImage = nil;
buttonImage = [UIImage imageNamed:@"button_image"];
pressedButtonImage = [UIImage imageNamed:@"button_pressed_image"];
customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setImage : buttonImage forState : UIControlStateNormal];
[customButton setImage : pressedButtonImage forState : UIControlStateHighlighted];
[customButton addTarget : self action : @selector(buttonTapped) forControlEvents : UIControlEventTouchUpInside];
customButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
UIView *container = [[UIView alloc] initWithFrame:(CGRect){0.0, 0.0, buttonImage.size.width, buttonImage.size.height}];
container.backgroundColor = [UIColor clearColor];
[container addSubview:customButton];
UIBarButtonItem *customToolbarButton = [[UIBarButtonItem alloc] initWithCustomView:container];
// add the custom button to the toolbar
self.navigationBar.topItem.rightBarButtonItem = self.addButtonItem;