iOS中UITableView的背景颜色与图片改变 改变iOS应用中UITableView的背景颜色与背景图片的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

iOS中UITableView的背景颜色与图片改变 改变iOS应用中UITableView的背景颜色与背景图片的方法

ForeverYoung21   2021-03-23 我要评论
想了解改变iOS应用中UITableView的背景颜色与背景图片的方法的相关内容吗,ForeverYoung21在本文为您仔细讲解iOS中UITableView的背景颜色与图片改变的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:iOS,UITableView,下面大家一起来学习吧。

改变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];


这种情况下背景图片不会动,即无论多少行看到的都是同样的背景。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们