I want to center the header on the tableview, however I have 2 problems. First I don’t have the correct height and second the UILabel doesn’t look like the default header – font/font size/color etc… Is there a better way to center it, and/or is there a way to make it look like the default header.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger) section
{
//section text as a label
UILabel *lbl = [[UILabel alloc] init];
lbl.textAlignment = UITextAlignmentCenter;
lbl.text = @"Header";
[lbl setBackgroundColor:[UIColor clearColor]];
return lbl;
}
You must also implement tableView:heightForHeaderInSection to adjust your header height :
In the UITableViewDelegate Protocol Reference doc you find :
For centering the Header label you must specify the label frame before setting its aligment to center.
For getting the standart font, use SystemFontOfSize:
Also beware you are creating a memory leak you are supposed to return an autoreleased view
Try something like this :
Hope this helps,
Vincent