首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在左栏控制器或右栏控制器旁边添加按钮

如何在左栏控制器或右栏控制器旁边添加按钮
EN

Stack Overflow用户
提问于 2011-05-13 14:27:27
回答 6查看 1.3K关注 0票数 1

我怎么才能在左边的barButton旁边或者rightbarButton旁边添加按钮,我的意思是我需要在标题栏上有两个以上的按钮,这是可能的吗?

提前感谢

EN

回答 6

Stack Overflow用户

发布于 2011-05-13 14:32:33

this blog post引出

将工具栏视为容器,而不是UIView对象。由于UIToolBar是基于UIView的,因此可以使用上面的技巧将其添加到导航栏的右侧。下面的代码显示了如何在右侧添加两个标准按钮:

代码语言:javascript
运行
复制
// 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的帖子

Adding buttons to navigation bar

票数 0
EN

Stack Overflow用户

发布于 2011-05-13 14:35:27

你可以在你的leftBarButton中使用带有两个按钮的视图-

代码语言:javascript
运行
复制
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftBtnsView];
票数 0
EN

Stack Overflow用户

发布于 2011-05-14 00:28:15

我建议使用UISegmentedControl来控制所有的按钮,并使用[[UIButton alloc] initWithCustomView:]来显示片段控件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5988058

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档