Reputation: 17834
Is there a better way of adding a button at the bottom of a table view as seen below? The solutions I found involved inserting a button inside the header or footer of an existing section, seems kinda hacky to me.
Upvotes: 2
Views: 3334
Reputation: 497
Create a new UIView and set the view to the tableview's footer view and add the button as the subview of the new UIView. Also, set the height for the footer in heightForFooterInSection method.
Something like this in viewDidLoad,
- (void)viewDidLoad
{
UIView *newView = [[UIView alloc]initWithFrame:CGRectMake(10, 70, 300, 45)];
submit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[submit setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//[submit setTitleColor:[UIColor colorWithWhite:0.0 alpha:0.56] forState:UIControlStateDisabled];
[submit setTitle:@"Login" forState:UIControlStateNormal];
[submit.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[submit setFrame:CGRectMake(10.0, 15.0, 280.0, 44.0)];
[newView addSubview:submit];
[self.tableView setTableFooterView:newView];
[super viewDidLoad];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 50;
}
Upvotes: 5
Reputation: 6710
The view you are looking at is a UITableView. If you have several entries, then the info for this person would scroll off the screen along with the "Delete" button. Putting the button in the table footer would allow it to scroll along with the table. The table footer is outside of any section.
If your view does not have any scrolling or a dynamic sized table view you could just add it to the bottom of the view.
Upvotes: 2
Reputation: 946
you can add a UIView
and then add a UIButton
into that so that UIButton
could not autoresized to fit to width.
Upvotes: 0
Reputation: 8180
How about using a toolbar with a delete button? IMHO, it would look "nicer".
Upvotes: 0