Поместите UIBarButtonItem в UIToolBar с PhoneGap - PullRequest
0 голосов
/ 26 января 2012

Я использую PhoneGap 1.3 и пытаюсь создать кнопку добавления iOS в правой части моей панели инструментов; однако метод createToolBarItem не имеет никакой возможности установить позицию элемента. Как я могу это сделать? Вот фрагмент кода от NativeControls.h:

//create the toolbar in `createToolBar` method://
toolBar = [[UIToolbar alloc] initWithFrame:toolBarBounds];

//....set some toolbar options like .hidden, .barStyle, etc.//
[toolBar setFrame:toolBarBounds];
[self.webView setFrame:webViewBounds];

//add the toolbar to the webview
[self.webView.superview addSubView:toolBar];


//create the button item in `createToolBarItem` method:
item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd target:self action:@selector(toolBarButtonTapped:)];
[toolBarItems insertObject:item atIndex:[tagId intValue]];
[item release];

//then in `showToolBar` method//
[toolBar setItems:toolBarItems animated:NO];

1 Ответ

0 голосов
/ 15 июня 2012

Вы, наверное, уже узнали, но вам нужно добавить UIBarButtonSystemItemFlexibleSpace слева от вашей кнопки, чтобы выровнять ее по правому краю.

В Phonegap, от JS сделать:

nativeControls.createToolBarItem("spacer", "", "UIBarButtonSystemItemFlexibleSpace", "");
...