改变UITableView的headerView、footerView背景颜色

改变UITableView的header、footer背景颜色,这是个很常见的问题。之前知道的一般做法是,通过实现tableView: viewForHeaderInSection:返回一个自定义的View,里面什么都不填,只设背景颜色。但是今天发现一个更简洁的做法。

对于iOS 6及以后的系统,实现这个新的delegate函数即可:

- (void)tableView:(UITableView*)tableView willDisplayFooterView:(UIView*)view forSection:(NSInteger)section {    view.tintColor= [UIColor clearColor];

}

还可以改变文字的颜色:

- (void)tableView:(UITableView*)tableView willDisplayFooterView:(UIView*)view forSection:(NSInteger)section{    UITableViewHeaderFooterView *footer = (UITableViewHeaderFooterView *)view;    

[footer.textLabel setTextColor:[UIColor whiteColor]];

}

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

推荐阅读更多精彩内容