iOS tableView每组间距的背景颜色

利用tableview的代理方法来实现自定义背景色,非常简单的几句代码

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 8;//每组间距的高度最好设置为宏,和下面的view的高度保持一致
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return .001;//貌似这样设置效果好点
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 8)];
    //自定义颜色
    view.backgroundColor = [UIColor cyanColor];
    return view;
}

觉得可以star我吧!💕💕

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容