改变UITableView的headerView、footerView背景颜色
2015-08-06 10:34
489 查看
改变UITableView的headerView、footerView背景颜色
hampotato 2.3k 1月6日
发布
推荐 0 推荐
收藏 1 收藏,2.2k 浏览
问题
改变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]]; }
错误的尝试
写这篇文章的目的,主要是想记录两种错误的尝试。当看到这个Delegate函数时,第一反应是想当然地这样做:
错误尝试1
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section { view.backgroundColor = [UIColor clearColor]; }
这样做是无效的,无论对什么颜色都无效。
错误尝试2
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section { UITableViewHeaderFooterView *footer = (UITableViewHeaderFooterView *)view; footer.contentView.backgroundColor = [UIColor redColor]; }
这样做设成不透明的颜色就没问题。但设成clearColor,看到的还是灰色。
相关文章推荐
- iTunes Connect 开发者指南 (iTunes Connect Developer Guide)
- Question2Answer 安全
- UIViewContentMode,ios图片排版
- NSValue的个人想法
- IOS UIColor 自定义颜色
- Distinct Subsequences
- altibase MDB的创建sequence的举例
- question2answer优化
- Atomic Builtins - Using the GNU Compiler Collection (GCC) GCC 提供的原子操作
- cleaning selected projects has encountered a problem errors occurred during build
- hdoj.1297 Children’s Queue【大数+排列组合】 2015/08/06
- MSBUildToolsPath is not specified for the ToolsVersion
- 完美解决某些字符插入到mysql数据库出现incorrect string value的问题
- HDOJ 1242 Rescue(bfs+优先队列)
- HDU 1242:Rescue 【bfs】
- 多个UIImage合并成一个UIImage
- UICollectionView初探
- 【iOS学习笔记】生成带文本的UIImage
- Message MessageQueue Runnable Looper 和Handler的关系理解
- UI0805_Page