интервал rightBarButtonItems в UINavigationBar - PullRequest
8 голосов
/ 09 февраля 2012

Я использую свойство rightBarButtonItems UINavigationBar, чтобы добавить две кнопки в правой части панели навигации. можно ли увеличить расстояние между этими двумя кнопками?

спасибо

Ответы [ 2 ]

6 голосов
/ 09 февраля 2012

Вы можете добавить элемент UIBarButtonSystemItemFlexibleSpace между двумя кнопками.

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                      target:nil
                                                                      action:nil];
1 голос
/ 01 марта 2013

Мне не удалось заставить гибкое пространство работать в моей ситуации, но вот код, который я использовал для позиционирования rightBarButtonItem: Обратите внимание, я поставил границу вокруг UIView, чтобы вы могли видеть, как это выглядит имея изображение там.

UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(89,40,100,30)];
containerView.layer.borderColor = [[UIColor redColor] CGColor];
containerView.layer.borderWidth = 1.0;
UIImage *image = [UIImage imageNamed:@"nav-icon.png"];
UIButton *navigationButton = [UIButton buttonWithType:UIButtonTypeCustom];
[navigationButton setFrame:CGRectMake(67,0,25,25)];
[navigationButton setImage:image forState:UIControlStateNormal];
[containerView addSubview:navigationButton];

UIBarButtonItem *navigationBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:containerView];

self.navigationItem.rightBarButtonItem = navigationBarButtonItem;
...