Customise UITableViewHeaderFooterView through XIB

Create a UIView class through XIB, and change it as to be the subclass of UITableViewHeaderFooterView.

Remember: Change the background color of the UITableViewHeaderFooterView to be "Default" in the XIB.

ELSE, you will get this warning:

"Setting the background color on UITableViewHeaderFooterView has been deprecated. Please use contentView.backgroundColor instead."

then, HOW to change the background color of UITableViewHeaderFooterView:

- (void)awakeFromNib
    [super awakeFromNib];
    self.backgroundView = ({
        UIView * view = [[UIView alloc] initWithFrame:self.bounds];
        view.backgroundColor = [UIColor whiteColor];

And, How to use this customised UITableViewHeaderFooterView:

Claim it first:

[self.tableView registerNib:[UINib nibWithNibName:@"HeaderView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"HeaderViewIdentifier"];

reload the table view:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    return 80;

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    HeaderView *view = (HeaderView *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HeaderViewIdentifier"];
    return view;

个人分类: iOS Dev
上一篇App Transport Security (ATS)
下一篇add "shadow+border+corner" specially for UIView
想对作者说点什么? 我来说一句