我怎么才能在左边的barButton旁边或者rightbarButton旁边添加按钮,我的意思是我需要在标题栏上有两个以上的按钮,这是可能的吗?
提前感谢
发布于 2011-05-13 14:32:33
从this blog post引出
将工具栏视为容器,而不是UIView对象。由于UIToolBar是基于UIView的,因此可以使用上面的技巧将其添加到导航栏的右侧。下面的代码显示了如何在右侧添加两个标准按钮:
// create a toolbar to have two buttons in the right
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// create a spacer
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
[bi release];
// create a standard "refresh" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
[buttons release];
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];还可以查看SO的帖子
发布于 2011-05-13 14:35:27
你可以在你的leftBarButton中使用带有两个按钮的视图-
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftBtnsView];发布于 2011-05-14 00:28:15
我建议使用UISegmentedControl来控制所有的按钮,并使用[[UIButton alloc] initWithCustomView:]来显示片段控件。
https://stackoverflow.com/questions/5988058
复制相似问题