【iOS 1 行代码系列】之 一行代码搞定TableView组头悬停

场景:

UITableViewstyle 属性设置为 Plain
tableviewsection header 在滚动到界面顶端时
悬停 !


疑问:

1.如何在不使用Grouped时,让组头不悬停??
2.如何在不重写-scrollViewDidScroll: (示例) 方法时,让组头不悬停???


办法:

1.针对没有内容的 section header
直接设置 header view 的背景颜色为 clearColor
设置 tableview 的背景颜色为 section header 的背景颜色

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, kScreenWidth, 10);
    view.backgroundColor = [UIColor clearColor];
    return view;
}

2.针对有内容的 section header
- 使用 Grouped
- 参考 示例

猜你喜欢

转载自blog.csdn.net/xjh093/article/details/79895910