UITableView - change section header color

前端 未结 30 2898
不思量自难忘°
不思量自难忘° 2020-11-27 08:50

How can I change color of a section header in UITableView?

EDIT: The answer provided by DJ-S should be considered for iOS 6 and above. The accepted

30条回答
  •  感动是毒
    2020-11-27 09:29

     -(void) tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view
      forSection:(NSInteger)section
      {
            if ([view isKindOfClass: [UITableViewHeaderFooterView class]])
            {
                 UITableViewHeaderFooterView *castView = (UITableViewHeaderFooterView *) view;
                 UIView *content = castView.contentView;
                 UIColor *color = [UIColor whiteColor]; // substitute your color here
                 content.backgroundColor = color;
                 [castView.textLabel setTextColor:[UIColor blackColor]];
            }
     }
    

提交回复
热议问题