More than 1 rightBarButtonItem on navigation bar

前端 未结 9 976
清歌不尽
清歌不尽 2021-01-30 02:06

I would like to have two rightBarButtonItems on navigation bar. One for Edit and the other for Add.

Obviously I can\'t make it using Interface Builder.

Does anyb

相关标签:
9条回答
  • 2021-01-30 02:35

    You can do it from Interface Builder. What I have done in my app - just added UIView on left Item of navigation bar and placed 3 buttons in this view and connected their action. You can follow this to add more than one button in left/right navigation item.

    Refered: Toolbar items in sub-nib

    enter image description here

    0 讨论(0)
  • 2021-01-30 02:39

    Heres an example of how you can add two buttons as the rightbarbutton. The code below creates a segmentedcontrol containing up and down arrow buttons, which is then added as a customview for navigation's rightbarbutton:

    UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray array]];
        [segmentedControl setMomentary:YES];
        [segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"icon-triangle-up.png"] atIndex:0 animated:NO];
        [segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"icon-triangle-down.png"] atIndex:1 animated:NO];
        segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
        [segmentedControl addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
    
        UIBarButtonItem * segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView: segmentedControl];
        self.navigationItem.rightBarButtonItem = segmentBarItem;
    
    0 讨论(0)
  • 2021-01-30 02:39

    if someone is passing by, here is the swift answer :

    let barButton_array: [UIBarButtonItem] = [Button1, Button2]
    navigationItem.setRightBarButtonItems(barButton_array, animated: false)
    
    0 讨论(0)
提交回复
热议问题