xcode 以按钮为标题的 UINavigationBar。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8676368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UINavigationBar with buttons as title.
提问by random
I have done some digging and can't seem to get anything useful.
我已经做了一些挖掘,似乎无法得到任何有用的东西。
What I am trying to do is pretty basic but I'm not sure if their is:
我想做的是非常基本的,但我不确定它们是否是:
1. An easier way
1. 更简单的方法
2. Or if Apple will give it a "no no"
2. 或者如果苹果会给它一个“不不”
I have a view that is controlled via UINavigationController (obviously from the title of this post) and in it has an object/view.
我有一个通过 UINavigationController 控制的视图(显然来自这篇文章的标题),其中有一个对象/视图。
The view is fairly congested already with content. Not really congested but no more room to fit things comfortably.
该视图已经相当拥挤的内容。不是很拥挤,但没有更多的空间来舒适地放置东西。
The user needs to be able to rate this object by using a different number of starts (1-5).
用户需要能够通过使用不同的启动次数 (1-5) 来评价该对象。
The ideal way I would see this happening would be to have 5 star buttons (with images of course) set in the UINavigationBar title position (centered).
我看到这种情况发生的理想方式是在 UINavigationBar 标题位置(居中)设置 5 个星形按钮(当然还有图像)。
So look something like this:
所以看起来像这样:
___________________________________
| |
| Back * * * * * Action |
|_________________________________|
| |
| view down here |
| |
Any input would be verymuch appreciated and as always, thank you for your time!
非常感谢您的任何意见,并一如既往地感谢您的时间!
回答by Paul.s
You can just create your custom widget with the 5 star rating functionality and add it to the navigationItem
您可以使用 5 星评级功能创建自定义小部件并将其添加到导航项
self.navigationItem.titleView = customWidget;
回答by Legolas
On top of my head, my suggestion would be that you try using UIToolbar
and set it on top, and make it look like a navigationBar
. It's fairly easy to implement it and add UIButtons
and actions to it.
在我的头顶上,我的建议是您尝试使用UIToolbar
并将其设置在顶部,并使其看起来像navigationBar
. 实现它并对其进行添加UIButtons
和操作相当容易。
回答by Gank
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(chooseDataCenter:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"点我选择数据中心>" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 160.0, 40.0);
self.navigationItem.titleView =button;