【问题标题】:How can i add more than 10 buttons on a navigationbar in iphone application development?如何在 iphone 应用程序开发中的导航栏上添加 10 多个按钮?
【发布时间】:2012-01-07 05:13:21
【问题描述】:

在我的应用程序中,我必须在导航栏上添加 8 个按钮。所以这些按钮应该在视图中并且应该有一个上一个和下一个按钮是非常正常的。当我按下下一个按钮然后使用动画时,它将显示下一个按钮,这些按钮不在视图中并且与上一个按钮相同。

详情:

  1. UINavigation Bar -> leftBaritem[上一个按钮] + view + rightBaritem[下一个按钮];

  2. 视图将包含 8 个按钮。如果我再解释一下,它应该是这样的:

上一个 + |一个 |乙| C | D | E | F |克| H + 下一个

我什么时候按

下一个

然后它会显示如下:

上一个 + |乙| C | D | E | F |克| H + 下一个

喜欢这个

上一页

按钮。

编辑:

在这张图片中,一个视图中有三个按钮,但我有六个按钮可以添加到“仪表板、订单、产品”视图上。现在,当我按下“>”或“

【问题讨论】:

  • 导航栏,真的吗?我很想看到您尝试设计的 UI 的屏幕截图。这听起来可能会让用户感到困惑。为什么不使用页面控制器?
  • @MichaelDautermann:我已经编辑了我的问题,现在请帮助我。
  • 这不是您想要的,但它可能会帮助您入门:cocoacontrols.com/platforms/ios/controls/jsscrollabletabbar
  • @chris 是的,我需要这种酒吧..但我不知道该怎么做。

标签: iphone ios uiview uiscrollview uinavigationbar


【解决方案1】:

你做错了。您不应该试图将 8 个按钮强加到导航栏中。

您需要重新考虑您的界面。想到了两种合理的方法:

  • 使用标签栏。选项卡栏支持处理超出屏幕大小的选项。例如,内置的音乐应用有 10 个标签。

  • 将八个按钮放在导航控制器下的全屏视图中。当用户单击一个时,为该按钮按下相应的视图。用户可以弹回(使用导航控制器的正常后退按钮支持)来选择不同的按钮。

【讨论】:

【解决方案2】:

我解决这个问题的方式略有不同......

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(@"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];

}

它解决了...快乐编码... :))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-15
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多