Как я могу установить пользовательскую кнопку, где я хочу на UINavigationBar? - PullRequest
1 голос
/ 09 сентября 2011

У меня есть вид с UINavigationBar

Панель навигации позволяет мне только кнопку в фиксированном положении

С Фиксированным положением по бокам панели навигации ..

Iхочу настроить положение кнопки ... Любая идея ... поможет мне Спасибо заранее

Ответы [ 2 ]

1 голос
/ 09 сентября 2011

Вы не можете настроить положение кнопок на UINavigationItem, вы можете только установить rightBarButtonItem и leftBarButtonItem.

Если вам это действительно нужно, рассмотрите возможность использования панели инструментов.

Если вам нужна кнопка «Назад», как и кнопка «Назад» на панели навигации, создайте пользовательскую кнопку и используйте изображение.

Вот PSD , который поможет.

0 голосов
/ 09 сентября 2011

Вы можете расположить пользовательские кнопки внутри UINavigationItem. Вот как я добавил три кнопки справа:

// create a toolbar to have three buttons in the right (thanks Mart!)
tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 157, 44.01)];

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 1.0, 157.0, 44.1)];
[imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NavigationBarBackground" ofType:@"png"]]];
[tools addSubview:imgView];
[tools sendSubviewToBack:imgView];
[tools setTintColor:[UIColor colorWithRed:127/255.0 green:184/255.0 blue:72/255.0 alpha:1.0]];
[imgView release];

// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

UIBarButtonItem* bi = [[UIBarButtonItem alloc] 
                       initWithTitle:@"Filter" style:UIBarButtonItemStyleBordered target:self action:@selector(showFilter:)];

[buttons addObject:bi];
[bi release];

bi = [[UIBarButtonItem alloc]
      initWithImage:[UIImage imageNamed:@"Map.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showMap:)];

[buttons addObject:bi];
[bi release];

bi = [[UIBarButtonItem alloc] 
      initWithImage:[UIImage imageNamed:@"Favourite.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(saveSearch:)];
[buttons addObject:bi];
[bi release];

[tools setItems:buttons animated:NO];

[buttons release];

rightBarButton = nil;
rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:tools];

self.navigationItem.rightBarButtonItem = rightBarButton;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...