简体   繁体   中英

how to add UINavigationController UIToolbar to the top of the view not the bottom

I am trying to add a the UINavigationController UIToolbar to the top of the view, (under the navigation controller.

My view is a UITableViewController ... so there is that to deal with. Currently I am just positioning the UIToolbar that appears at the bottom of the view where I want it to display using

[self.navigationController.toolbar setFrame:CGRectMake(0, 60, 320, 30)];

this positions the toolbar in the correct place I would like it to appear, However there is a problem with where its positioned, which I will explain.

When you set a UINavigationController toolbar to be displayed it puts itself at the bottom of the view and pushes the UITableView up so the toolbar does not cover the tableview. However when I change the position of the toolbar the tableview still thinks the toolbar is at the bottom of the screen meaning the toolbar does not meet flush at the bottom of the screen how I would like it too.

So my question is how can I get the toolbar to display directly below the navigation controller bar and push the tableview down abit to accommodate for the toolbar in its new position.

I hope this all makes sense, Any help I would like to than in advance and below is the current code I am using (all be it basic I am still abit perplexed about whats going on behind the scenes for this to happen).

- (void) viewDidLoad
{
//..

    [self.navigationController setToolbarHidden:NO animated:YES];
    [self.navigationController.toolbar setFrame:CGRectMake(0, 60, 320, 30)];
    self.navigationController.toolbar.tintColor = [UIColor lightGrayColor];

//..
}

update

this is currently what the toolbar is doing to my tableview

在此输入图像描述

Call setFrame on your UITableView to move it into positon.

float y = self.navigationController.toolbar.frame.origin.y + self.navigationController.toolbar.frame.size.height;
[myTable setFrame:CGRectMake(0, y, self.view.frame.size.width, self.view.frame.size.height-y)];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM