Reputation: 1466
I want to add a view under the header of a section in a UITableView
. Is that possible? Here's my code so far, with that code it replaces the section:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 4) {
return 10;
} else
{
return 20;
}
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 4) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 10)];
view.backgroundColor = [UIColor blackColor];
return view;
} else {
return nil;
}
}
Upvotes: 1
Views: 251
Reputation: 130193
Conceptually, I wouldn't think of this as adding another view underneath your header. Instead, consider making your header the height that you want the header to be + the height of the black line. Then, all you have to do is create an additional view (the black line) and add it as a sub view of the header, ex
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 10)];
view.backgroundColor = [UIColor whiteColor];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, view.frame.size.height - 2.0, view.frame.size.width, 2.0)];
[lineView setBackgroundColor:[UIColor blackColor]];
[view addSubview:lineView];
Upvotes: 1