How do I place a button below a UITableView but above a TabBar so that the UIButton is stationary (not scrolling with tableview) ?
Here is a picture of what I want to accomplice: http://i.imgur.com/dY4CsDC.png
How do I place a button below a UITableView but above a TabBar so that the UIButton is stationary (not scrolling with tableview) ?
Here is a picture of what I want to accomplice: http://i.imgur.com/dY4CsDC.png
Subclass a UIViewController and place a UITableView and a UIButton as subviews. See the accepted answer on this question.
UITableView sticky footer / custom toolbar implementation
If there is only one section in your tableView, you could also put your UIButton in a tableView footer cell. Using...
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
See the documentation for more detail
Simple!
In your UIViewController class, where You use Your tableview, You simply add to the same ViewControllers view button as subview and reposition both of them so that each of them would have it's own space.
So..
_tableView = [[UITableView alloc] init];
[_tableView setDataSource:self];
[_tableView setDelegate:self];
[_tableView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
// Use 64 to allow for the naviation bar on top and 160 to allow for tabbar and button
[_tableView setFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-160)];
[[self view] addSubview:_tableView];
_aButtonUnderTableView = [UIButton new];
[_aButtonUnderTableView setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];
// use 50 for the height
[_aButtonUnderTableView setFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.frame.size.width, 50)];
[_aButtonUnderTableView setTitle:@"Custom Button Title" forState:UIControlStateNormal];
[_aButtonUnderTableView setBackgroundColor:[UIColor redColor]];
[_aButtonUnderTableView addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:_aButtonUnderTableView];
Now - tableview should have all available space but leaving 100 pix offset from bottom. And it will autoresize, leaving 100 pix at the bottom in case of double statusbar.
And button will stay at the bottom (even in case of double status bar) - always having visible 100 pix height.
Assuming that the downloaded data will be shown in UITableView above, you should create a UIView
and with UIButton
(Download more stuff) and set this UIView
as tableFooterView
of the above UITableView
.
tableView.tableFooterView = downloadView;