- 在headerView里面:
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.layer.zPosition = 0;
}
return self;
}
初始化的时候加上加上self.layer.zPosition = 0
背景图初始化也加上这个属性
- (UIImageView *)backImgV
{
if (!_backImgV) {
_backImgV = [[UIImageView alloc] init];
_backImgV.image = [UIImage imageNamed:@"backImg"];
_backImgV.layer.zPosition = 1;
}
return _backImgV;
}
- cell里面初始化 self.layer.zPosition 的值大于headerView里面的
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.layer.zPosition = 100;
}
return self;
}
或者在awakeFromNib里面设置也可以
- viewcontroller里面设置headerView
- (UICustomeHeaderVIew *)headerView
{
if (!_headerView) {
_headerView = [[UICustomeHeaderVIew alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 170)];
}
return _headerView;
}
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 118)];
[header addSubview:self.headerView];
self.tableView.tableHeaderView = header;
[self.tableView sendSubviewToBack:header];
最后看一下效果图: