UITableView - change section header color

前端 未结 30 2928
不思量自难忘°
不思量自难忘° 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

    Set the background and text color of section area: (Thanks to William Jockusch and Dj S)

    - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
    {
        if ([view isKindOfClass: [UITableViewHeaderFooterView class]]) {
            UITableViewHeaderFooterView* castView = (UITableViewHeaderFooterView*) view;
            castView.contentView.backgroundColor = [UIColor grayColor];
            [castView.textLabel setTextColor:[UIColor grayColor]];
        }
    }
    

提交回复
热议问题