adding buttons to ui navigation controller bottom bar

后端 未结 1 1650
忘掉有多难
忘掉有多难 2021-01-13 09:22

I am able to unhide the navigation controller bottom bar by using the following code

[self.navigationController setToolbarHidden:NO];

But

1条回答
  •  鱼传尺愫
    2021-01-13 10:02

    In the viewDidLoad method of each view controller that you are displaying within the navigation controller, add code such as the following:

    //set up the toolbar
    [self.navigationController setToolbarHidden:NO];
    [self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque];  //for example
    
    //set the toolbar buttons
     [self setToolbarItems:[NSArray arrayWithObjects:button1, button2, nil]];  
    

    In this case, button1 and button2 are IBOutlet properties of the view controller, with the actual buttons defined as UIBarButtonItem within IB (but not part of the view hierarchy within IB).

    Alternatively you can use code to create the buttons - like this:

    UIBarButtonItem* button1 = [[[UIBarButtonItem alloc] initWithTitle:@"Button Text" style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)] autorelease];
    

    0 讨论(0)
提交回复
热议问题