您的位置:首页 > 产品设计 > UI/UE

Customise UITableViewHeaderFooterView through XIB

2015-11-19 16:19 441 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息