使用PhoneGap在UIToolBar中定位UIBarButtonItem



我正在使用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];

您现在可能已经发现了,但您必须在按钮的左侧添加一个UIBarButtonSystemItemFlexibleSpace才能使其右对齐。

在Phonegap中,来自JS do:

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

最新更新