Position a UIBarButtonItem in a UIToolBar with PhoneGap

578 views Asked by At

I'm using PhoneGap 1.3 and am trying to create an iOS add button on the right side of my toolbar; however, the createToolBarItem method does not have any option to set the position of the item. How can I do this? Here is a snippet of code from 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

There are 1 answers

0
julien_c On

You probably found out by now, but you have to add a UIBarButtonSystemItemFlexibleSpace to the left of your button to have it right-aligned.

In Phonegap, from JS do:

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