如何在iPhone应用程序开发的导航栏上的分段控制器上添加下一个和上一个按钮? [英] How can i add a next and previous button at the segmented Controller on a navigation bar in iphone application development?
问题描述
我很麻烦....如何在分段栏中设置下一个和上一个按钮/箭头...如果有人需要我的问题的简要说明,请参阅此链接...
I am in great trouble....How can i set next and previous button/arrow at my segmented bar...if anyone need brief about my problem then please see this link...How can i add a next and previous button at the segmented Controller?
我已附上图片以了解问题所在.所以请任何人帮助我....
i have attached an image to understand the problem...so anybody help me please....
注意:在我当前的项目中,有五个以上的按钮要添加到分段栏上,因此当我按下一个/上一个箭头时,分段栏应该从他的位置移开.如果我的问题对您不清晰,则请查看我的另一个链接....
NOTE THAT: In my current project it has more than 5 buttons to add at the segmented bar so when i will press next/previous arrow then segmented bar should be move from his place.If my question is not clear to you then please see my another link....
预先感谢
UIBarButtonItem *previousBarButtonItem = [[UIBarButtonItem alloc] //init];
initWithTitle:@"<"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(previousBarButtonAction:)];
self.navigationItem.leftBarButtonItem = previousBarButtonItem;
[previousBarButtonItem release];
UIBarButtonItem *nextBarButtonItem = [[UIBarButtonItem alloc] //init];
initWithTitle:@">"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(nextBarButtonAction:)];
self.navigationItem.rightBarButtonItem = nextBarButtonItem;
[nextBarButtonItem release];
//This Portion For UIToolbar
topToolBar = [UIToolbar new];
topToolBar.barStyle = UIBarStyleDefault;
[topToolBar sizeToFit];
topToolBar.frame = CGRectMake(50, 410, 280, 50);
//Add buttons
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(pressButton1:)];
UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(pressButton2:)];
UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self action:@selector(pressButton3:)];
//Use this to put space in between your toolbox buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
//Add buttons to the array
NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil];
//release buttons
[systemItem1 release];
[systemItem2 release];
[systemItem3 release];
[flexItem release];
//add array of buttons to toolbar
[topToolBar setItems:items animated:NO];
self.navigationItem.titleView = topToolBar;
这是我当前的编码位置,现在我在uitoolbar中有4个按钮,但是只能看到3个按钮,所以当我要按下next或上一个按钮以查看uitoolbar框架之外的其他按钮时,我想移动此工具栏??
this is my current coding position now i have 4 buttons in the uitoolbar but only 3 button can see so i want to move this toolbar when i will press next or previous button to see the others button whose are out of frame of uitoolbar??
我可以使用uiview动画滚动导航栏项,但是现在我的问题是,当我按下next/prev按钮时,它会根据uitoolbar坐标的更改从当前位置移动,并在pre /下一个baritem框架,该框架不在uitoolbar项中.但是应该在uiview中使用,并且应该在uiview中更改坐标,而不是超出视图范围...现在告诉我该怎么办.
I able to scroll the navigation bar item using uiview animation but now my problem is when i press the next/prev button then it is moving from the current place according to the changing of the coordinate of the uitoolbar and moving over the pre/next baritem frame whose are not in the uitoolbar items. but it should be wothin a uiview and should change the coordinate within the uiview not out of the view...now tell me what can i do for this problem.
推荐答案
首先,在图中看到的NavigationBar实际上是UIToolBar
.不幸的是,不可能再在UINavigationBar
上添加控件.但是您可以使用UIToolBar
实现完全相同的UI,您可以在其中添加任何控件.
Firstly in figure the NavigationBar you are seeing is actually UIToolBar
. Unfortunately it is not possible to add anymore controls on the UINavigationBar
. But you can achieve exactly same UI with UIToolBar
where you can add any controls.
因此要实现此目的,请使用UIToolBar
而不是UINavigationBar
.还可以使用具有自定义标题的UIBarButtonItem
来实现 Next 和 Previous 功能.
So to achieve this use UIToolBar
and not UINavigationBar
. Also use UIBarButtonItem
with custom title to achieve Next and Previous functionality.
编辑
以下是一些链接,例如UIToolBar
Here are few links for example of UIToolBar
- http://www.codeproject .com/Articles/43658/如何制作带有UIToolbar的工具栏
- http://osmorphis.blogspot.com /2009/05/multiple-buttons-on-navigation-bar.html
- http://atastypixel.com/blog/制作uitoolbar和uinavigationbars背景完全透明/
- http://www.codeproject.com/Articles/43658/How-to-Make-a-Toolbar-with-UIToolbar
- http://osmorphis.blogspot.com/2009/05/multiple-buttons-on-navigation-bar.html
- http://atastypixel.com/blog/making-uitoolbar-and-uinavigationbars-background-totally-transparent/
但这全部说明了使用代码的原因.代替使用 Interface Builder ,使用UIToolBar
变得太容易了(如果编码不是很重要).
But this all explains using codes. Instead using Interface Builder, it becomes too easy to use UIToolBar
(if coding is not so important).
这篇关于如何在iPhone应用程序开发的导航栏上的分段控制器上添加下一个和上一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!