I have a UITableView
of static
cells, created using storyboards
with two sections. I use the following code to change the look of section headers
.
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 1, 320, 20);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor lightGrayColor];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(-1.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:10];
label.text = sectionTitle;
UIView *view = [[UIView alloc] init];
[view addSubview:label];
return view;
}
It looks the way I want, but when scrolling tableView
, the label
in the first Header doesn't scroll with the UIView
. It stays on the middle of the screen. As for the label
in the second header, it behaves like it is supposed to.