关闭

Customise UITableViewHeaderFooterView through XIB

标签: UITableViewHeaderFooXIBcontentViewbackgroundColor
1762人阅读 评论(0) 收藏 举报
分类:


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];
        view;
    });
}

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;
}





0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14712次
    • 积分:466
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:4篇
    • 译文:22篇
    • 评论:1条
    文章分类
    最新评论