UITableView - change section header color

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

    If you don't want to create a custom view, you can also change the color like this (requires iOS 6):

    -(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 colorWithWhite:0.85 alpha:1.]; // substitute your color here
            content.backgroundColor = color;
        }
    }
    

提交回复
热议问题