刚开始在继承
UITableViewHeaderFooterView
的自定义sectionHeader内部,设置self.backgroundColor = [UIColor whiteColor];
结果依旧显示灰色bash而后开始在代理方法
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
里,设置footer.backgroundColor
,依旧失败spa
在代理方法- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
里设置backgroundView
:代理
footer.backgroundView = [[UIImageView alloc] initWithImage:[UIImage ehs_imageWithColor:kBackgroundColor_Gray size:CGSizeMake(SCREEN_WIDTH, kSectionFooterHeight)]];
复制代码
网上一搜,会出现不少,大体都是在scroll的代理方法里设置tableview.contentInset
code
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 50;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
复制代码
UITableview处理section的不悬浮,禁止section停留的方法,主要是这段代码
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.tableView)
{
UITableView *tableview = (UITableView *)scrollView;
CGFloat sectionHeaderHeight = kSectionHeaderHeight;
CGFloat sectionFooterHeight = kSectionFooterHeight;
CGFloat offsetY = tableview.contentOffset.y;
HMLog(@"offsetY---%f",offsetY);
if (offsetY >= 0 && offsetY <= sectionHeaderHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);
}else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);
}else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), 0);
}
}
}
复制代码
但其实仍是没有用,依旧会有bug,亲测的方法是改变table的style继承
UITableViewStyleGrouped
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - Height_NavBar - kTopTailViewHeight)];
string
|| 改成:it
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - Height_NavBar - kTopTailViewHeight) style:UITableViewStyleGrouped];
io