在navigationBar中间的按钮 [英] Button in the middle of navigationBar
问题描述
我想创建一个自定义导航栏。
I want to create acustom navigation bar.
我知道我们可以在导航栏中间使用UIButton而不是标题,但是我们可以制作一些看起来像这张照片?
I know that we can use UIButton in the middle instead of title in the navigation bar, but can we make something that look like this picture?
如你所见,我们在这个导航栏的中间有三个不同的按钮。您能否与我分享您的想法我们如何在iPhone中实现这样的事情?
As you see we have three different buttons in the middle of this navigation bar. Can you share your idea with me how we can implement such a thing in iPhone?
推荐答案
假设您使用的是导航控制器可以将navigationBar的titleView属性设置为UIView容器,该容器包含中间的三个按钮(以及两组三个点)。代码看起来像这样:
Assuming you are using a Navigation Controller you can set your navigationBar's titleView property to a UIView container that holds the three buttons in the middle (and the two sets of three dots). The code would look like something like this:
UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
buttonContainer.backgroundColor = [UIColor clearColor];
UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom];
[button0 setFrame:CGRectMake(0, 0, 44, 44)];
[button0 setBackgroundImage:[UIImage imageNamed:@"button0.png"] forState:UIControlStateNormal];
[button0 addTarget:self action:@selector(button0Action:) forControlEvents:UIControlEventTouchUpInside];
[button0 setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];
//add your spacer images and button1 and button2...
self.navigationItem.titleView = buttonContainer;
或者你当然可以在IB中完成这一切。
Or you could do this all in IB of course.
这篇关于在navigationBar中间的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!