【问题标题】:Displaying multiple buttons in a navigation bar在导航栏中显示多个按钮
【发布时间】:2014-11-17 21:17:21
【问题描述】:

在我的应用程序中,我想显示 2 个按钮(每个按钮都有不同的操作)来代替导航栏的 rightbarbutton。我该怎么做?

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    这是一个您希望它工作并提供帮助的代码

    把下面的代码放进去

     -(void)viewWillAppear:(BOOL)animated 
      {
         UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)];
         tools.tintColor = [UIColor clearColor];
    
         [tools setBarStyle:UIBarStyleBlackTranslucent];
         tools.barStyle = -1; // clear background
         NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];
    
        // Create a standard refresh button.
    
         UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
         [button setImage:[UIImage imageNamed:@"Settings.png"] forState:UIControlStateNormal];
         [button addTarget:self action:@selector(resetpass) forControlEvents:UIControlEventTouchUpInside];
    [button setFrame:CGRectMake(0, 0, 30,30 )];
    bi = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    [buttons addObject:bi];
    [bi release];
    
    bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    bi.width = 2.0f;
    [buttons addObject:bi];
    [bi release];
    
    // Add profile button.
    bi = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(createnewFolders)];
    bi.style = UIBarButtonItemStyleBordered;
    [buttons addObject:bi];
    [bi release];
    
    // Add buttons to toolbar and toolbar to nav bar.
    [tools setItems:buttons animated:NO];
    [buttons release];
    twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
    [tools release];
    
    self.navigationItem.leftBarButtonItem = twoButtons;
    
    [twoButtons release];
     }
    

    谢谢

    【讨论】:

      【解决方案2】:

      我相信this post 会回答您的问题。

      但是,需要更多信息才能正确回答您的问题。 iOS版本等等。不过,该答案似乎符合您的要求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-18
        • 2013-01-20
        • 1970-01-01
        • 2019-01-11
        • 1970-01-01
        • 2012-12-08
        • 2018-10-24
        相关资源
        最近更新 更多