I have a view that was created with all of the default UITableView
stuff, but now I need to add a header area above where the UITableView
is (so th
You can use UITableViewDelegate
methods to create a custom header view for a table and specify the height, namely tableView:viewForHeaderInSection:
and tableView:heightForHeaderInSection:
. You can add whatever you like to the view. Here's an example that adds a right aligned UILabel
:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.frame.size.width,30)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, headerView.frame.size.width-120.0, headerView.frame.size.height)];
headerLabel.textAlignment = NSTextAlignmentRight;
headerLabel.text = [titleArray objectAtIndex:section];
headerLabel.backgroundColor = [UIColor clearColor];
[headerView addSubview:headerLabel];
return headerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30.0;
}