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;
}
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;
}
相关文章推荐
- 加载带有手势识别器的XIB文件需注意哪些问题
- Auto Layout on iOS Versions prior to 6.0 解决办法
- App整体颜色风格
- swift 代码加载xib storyboard
- UITableViewHeaderFooterView背景透明
- 九宫格--xib,MVC封装
- OC笔记 - UITableView(2015.2.13)
- OC笔记 - 模型对象、instancetype、xib的加载、UILabel、UIFont、UIButton的常见设置(2015.2.5)
- xib中设置view的圆角
- ios-(Xib的使用) 工作随笔
- 使用XIB自定义UIView
- IOS xib,文件加载笔记
- IOS2.0-xib的封装
- IOS2.1-应用管理示例(plist,模型,xib封装综合小示例)
- IOS1.9-xib的使用
- ios9 XIB加载缓慢
- Xocde7 里面Xib的使用
- 运行项目编译报错
- iOS小问题——关于使用IQKeyBoardManager第三方的坑
- 使用xib封装一个自定义view