How can i add more than 10 buttons on a navigationbar in iphone application development?(如何在 iphone 应用程序开发中的导航栏上添加 10 多个按钮?)
问题描述
在我的应用程序中,我必须在导航栏上添加 8 个按钮.所以这些按钮应该在视图中并且应该有一个上一个和下一个按钮是非常正常的.当我按下下一个按钮然后使用动画时,它将显示下一个按钮,这些按钮不在视图中并且与上一个按钮相同.
详情:
UINavigation Bar -> leftBaritem[上一个按钮] + view + rightBaritem[下一个按钮];
视图将包含 8 个按钮.如果我再解释一下,它应该是这样的:
<块引用>
上一个 + |一个 |乙|C |D |E |F |克|H + 下一个
我什么时候按
<块引用>下一个
然后它会显示如下:
<块引用>上一个 + |乙|C |D |E |F |克|H + 下一个
喜欢这个
<块引用>上一页
按钮.
在这张图片中,一个视图中有三个按钮,但我有六个按钮可以添加到仪表板、订单、产品"视图上.现在当我按下>"或<"时或左/右栏项目,然后它将显示导航栏的按钮,这些按钮不在视图中.
我解决这个问题的方式略有不同......
在 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];
然后在我的 function
中,我创建了我的菜单 buttons
,它看起来像 navigation bar
-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{NSLog(@"插入菜单栏按钮创建函数");for (int i = 0; i < totalNoOfButtons; i++) {UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[按钮 addTarget:self action:@selector(mybuttons:) forControlEvents:UIControlEventTouchUpInside];如果(我==0){[button setTitle:[NSString stringWithFormat:@"Dashboard"] forState:UIControlStateNormal];//带标题}否则如果(i==1){[button setTitle:[NSString stringWithFormat:@"Order"] forState:UIControlStateNormal];//带标题}否则如果(i==2){[button setTitle:[NSString stringWithFormat:@"Product"] forState:UIControlStateNormal];//带标题}否则如果(i==3){[button setTitle:[NSString stringWithFormat:@"Customers"] forState:UIControlStateNormal];//带标题}否则如果(i==4){[button setTitle:[NSString stringWithFormat:@"Content"] forState:UIControlStateNormal];//带标题}否则如果(i==5){[button setTitle:[NSString stringWithFormat:@"Site Analysis"] forState:UIControlStateNormal];//带标题}否则如果(i==6){[button setTitle:[NSString stringWithFormat:@"Store Settings"] forState:UIControlStateNormal];//带标题}否则如果(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;按钮.标签=我;[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 a scrollView
and called my function
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];
Then in my function
i have created my menu buttons
which will be look like buttons on a navigation 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 多个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iphone 应用程序开发中的导航栏上添加 1
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01