如何在iphone应用程序开发中的导航栏上添加10个以上的按钮? [英] How can i add more than 10 buttons on a navigationbar in iphone application development?
问题描述
在我的应用程序中,我必须在导航栏上添加8个按钮。所以这些按钮应该在视图中并且应该有一个上一个和下一个按钮是非常正常的。当我按下下一个按钮然后使用动画时,它将显示下一个按钮,这些按钮不在视图中,与前一个按钮相同。
详细信息:
-
UINavigation Bar - > leftBaritem [上一个按钮] + view + rightBaritem [下一个按钮];
-
视图将包含8个按钮。如果我再解释一下,它应该是这样的:
上一页+ | A | B | C | D | E | F | G |我将按
next
然后它会显示如下:
之前的+ | B | C | D | E | F | G | H + next
这样的
上一页
按钮。
编辑:
在这张图片中,视图中有三个按钮,但我在视图Dashbord,order,Product上添加了六个按钮。现在,当我按>或<或左/右栏项目然后它将显示导航栏中不在视图中的按钮。
解决方案我解决这个问题略有不同方式....
在
viewDidLoad
我已经采取scrollView
并调用我的函数menuScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,40)];
menuScrollView.showsHorizontalScrollIndicator = FALSE;
menuScrollView.showsVerticalScrollIndicator = FALSE;
menuScrollView.bounces = TRUE;
[self createMenuWithButtonSize:CGSizeMake(70.0,30.0)withOffset:20.0f noOfButtons:7];
然后在我的
函数中
我创建了我的菜单按钮
,它看起来像导航栏上的按钮
- (void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons {
NSLog(@insert into the菜单栏按钮创建功能);
for(int i = 0; i< totalNoOfButtons; i ++){
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(mybuttons :) forControlEvents:UIControlEventTouchUpInside];
if(i == 0){
[button setTitle:[NSString stringWithFormat:@Dashboard] forState:UIControlStateNormal]; //标题为
}
else if( i == 1){
[button setTitle:[NSString stringWithFormat:@Order] forState:UIControlStateNormal]; //标题为
}
else if(i == 2){
[button setTitle:[NSString stringWithFormat:@Product] forState:UIControlStateNormal]; //标题为
}
else if(i == 3){
[button setTitle:[NSString stringWithFormat:@Customers] forState:UIControlStateNormal]; //标题为
}
else if(i == 4){
[button setTitle:[NSString stringWithFormat: @Content] forState:UIControlStateNormal]; //标题为
}
else if(i == 5){
[button setTitle:[NSString stringWithFormat:@Site Analysis] forState:UIControlStateNormal]; //标题为
}
else if(i == 6){
[button setTitle:[NSString stringWithFormat:@Store Settings] forState:UICo ntrolStateNormal]; //标题为
}
else if(i == 7){
[button setTitle:[NSString stringWithFormat:@CMS Settings] forState:UIControlStateNormal]; //标题为
}
button.frame = CGRectMake(i *(offset + buttonSize.width),8.0,buttonSize.width,buttonSize.height);
button.clipsToBounds = YES;
button.showsTouchWhenHighlighted = YES;
button.layer.cornerRadius = 0; //宽度的一半
//button.layer.borderColor=[UIColor clearColor];
button.layer.backgroundColor = [UIColor blueColor] .CGColor;
button.titleLabel.font = [UIFont systemFontOfSize:10];
button.layer.borderWidth = 0.0f;
button.tag = i;
[menuScrollView addSubview:button];
}
menuScrollView.contentSize = CGSizeMake((buttonSize.width + offset)* totalNoOfButtons,buttonSize.height);
[self.view addSubview:menuScrollView];
}
它解决了......快乐编码...: ))
In my application I have to add 8 buttons on a navigation bar..So it's very much normal that these button should be in a view and there should be one previous and next button. When i will press the next button then using animation it will show the next buttons whose are out of the view and same as for previous button.
For Details:
UINavigation Bar -> leftBaritem[previous button] + view + rightBaritem[next button];
view will contain 8 buttons. If I explain again then it should be look like this:
Previous + | A | B | C | D | E | F | G | H + next
when I will press
next
then it will show like this:
previous + | B | C | D | E | F | G | H + next
like this for
previous
button.
EDIT:
In this picture there are three button in a view but i have six button to add on the view "Dashbord , order , Product". Now when i will press ">" or "<" or left/right bar items then it will show the buttons of the nav bar which are out of the view.
解决方案I have solve this problem slightly different way....
In
viewDidLoad
I have take ascrollView
and called my functionmenuScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,40)]; menuScrollView.showsHorizontalScrollIndicator = FALSE; menuScrollView.showsVerticalScrollIndicator = FALSE; menuScrollView.bounces = TRUE; [self createMenuWithButtonSize:CGSizeMake(70.0, 30.0) withOffset:20.0f noOfButtons:7];
Then in my
function
i have created my menubuttons
which will be look like buttons on anavigation bar
-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{ NSLog(@"inserting into the function for menu bar button creation"); for (int i = 0; i < totalNoOfButtons; i++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(mybuttons:) forControlEvents:UIControlEventTouchUpInside]; if(i==0){ [button setTitle:[NSString stringWithFormat:@"Dashboard"] forState:UIControlStateNormal];//with title } else if(i==1){ [button setTitle:[NSString stringWithFormat:@"Order"] forState:UIControlStateNormal];//with title } else if(i==2){ [button setTitle:[NSString stringWithFormat:@"Product"] forState:UIControlStateNormal];//with title } else if(i==3){ [button setTitle:[NSString stringWithFormat:@"Customers"] forState:UIControlStateNormal];//with title } else if(i==4){ [button setTitle:[NSString stringWithFormat:@"Content"] forState:UIControlStateNormal];//with title } else if(i==5){ [button setTitle:[NSString stringWithFormat:@"Site Analysis"] forState:UIControlStateNormal];//with title } else if(i==6){ [button setTitle:[NSString stringWithFormat:@"Store Settings"] forState:UIControlStateNormal];//with title } else if(i==7){ [button setTitle:[NSString stringWithFormat:@"CMS Settings"] forState:UIControlStateNormal];//with title } button.frame = CGRectMake(i*(offset+buttonSize.width), 8.0, buttonSize.width, buttonSize.height); button.clipsToBounds = YES; button.showsTouchWhenHighlighted=YES; button.layer.cornerRadius = 0;//half of the width //button.layer.borderColor=[UIColor clearColor]; button.layer.backgroundColor=[UIColor blueColor].CGColor; button.titleLabel.font = [UIFont systemFontOfSize:10]; button.layer.borderWidth=0.0f; button.tag=i; [menuScrollView addSubview:button]; } menuScrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height); [self.view addSubview:menuScrollView]; }
and it solves...Happy Coding... :))
这篇关于如何在iphone应用程序开发中的导航栏上添加10个以上的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!