美文网首页iOS开发iOS学习开发iOS学习笔记
iOS tableView每组间距的背景颜色

iOS tableView每组间距的背景颜色

作者: OpenLee | 来源:发表于2016-10-31 15:20 被阅读558次

利用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我吧!💕💕

相关文章

网友评论

    本文标题:iOS tableView每组间距的背景颜色

    本文链接:https://www.haomeiwen.com/subject/iyrputtx.html