首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在UINavigationBar上想要的位置设置自定义按钮?

如何在UINavigationBar上想要的位置设置自定义按钮?
EN

Stack Overflow用户
提问于 2011-09-09 21:56:26
回答 2查看 358关注 0票数 1

我与UINavigationBar有一个视图

导航栏只允许我在固定位置使用按钮

固定位置在导航栏的两侧..

我想自定义按钮的位置...任何Idea...will帮我提前感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-09 22:10:13

您不能自定义按钮在UINavigationItem上的位置,您只能设置rightBarButtonItem和leftBarButtonItem。

如果您确实需要这样做,请考虑使用工具栏。

如果需要像导航栏的后退按钮一样的后退按钮,请创建自定义按钮并使用图像。

这里有一个PSD将会有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2011-09-10 00:05:38

您可以在UINavigationItem中定位自定义按钮。下面是我如何在右侧添加三个按钮的方法:

代码语言:javascript
运行
复制
// create a toolbar to have three buttons in the right (thanks Mart!)
tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 157, 44.01)];

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 1.0, 157.0, 44.1)];
[imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NavigationBarBackground" ofType:@"png"]]];
[tools addSubview:imgView];
[tools sendSubviewToBack:imgView];
[tools setTintColor:[UIColor colorWithRed:127/255.0 green:184/255.0 blue:72/255.0 alpha:1.0]];
[imgView release];

// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

UIBarButtonItem* bi = [[UIBarButtonItem alloc] 
                       initWithTitle:@"Filter" style:UIBarButtonItemStyleBordered target:self action:@selector(showFilter:)];

[buttons addObject:bi];
[bi release];

bi = [[UIBarButtonItem alloc]
      initWithImage:[UIImage imageNamed:@"Map.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showMap:)];

[buttons addObject:bi];
[bi release];

bi = [[UIBarButtonItem alloc] 
      initWithImage:[UIImage imageNamed:@"Favourite.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(saveSearch:)];
[buttons addObject:bi];
[bi release];

[tools setItems:buttons animated:NO];

[buttons release];

rightBarButton = nil;
rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:tools];

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

https://stackoverflow.com/questions/7362749

复制
相关文章

相似问题

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