这篇文章主要介绍了改变iOS应用中UITableView的背景颜色与背景图片的方法,将UITableView的header、footer设成clearColor时要注意实际效果是否真的变透明,需要的朋友可以参考下
改变UITableView的header、footer背景颜色
改变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]];
}
修改tableView的背景图片
修改UITableView的背景图片
1.图片显示为'PatternImage'模式。
// viewDidLoad
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundImage"]];
// cellForRowAtIndexPath
cell.backgroundColor = [UIColor clearColor];
这种情况下背景图片像地板砖一样平铺。拉动tableView背景图片会随着动,若行数超过背景图片的高度,会接着显示下一张图片。
2.正常的背景图片。
// viewDidLoad
self.tableView.backgroundColor= [UIColor clearColor];
UIImageView*imageView = [[UIImageView alloc]initWithImage:[UIImageimage Named:@"BackgroundImage"]];
self.tableView.backgroundView = imageView;
// cellForRowAtIndexPath
cell.backgroundColor = [UIColor clearColor];
这种情况下背景图片不会动,即无论多少行看到的都是同样的背景。
本文标题为:改变iOS应用中UITableView的背景颜色与背景图片的方法


基础教程推荐
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- Android中的webview监听每次URL变化实例 2023-01-23
- Android多返回栈技术 2023-04-15
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- android studio按钮监听的5种方法实例详解 2023-01-12
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- Flutter手势密码的实现示例(附demo) 2023-04-11