UITableView设置背景图

经常遇到要给tableView设置背景图片的问题,但如果直接设置背景 backgroundView的话,背景图不会显示,原因是 tableView上的cell默认是不透明的颜色,所以解决方法是 让 cell透明即可:

1.给tableView设置背景view
UIImageView *backImageView=[[UIImageViewalloc]initWithFrame:self.view.bounds];
[backImageView setImage:[UIImageimageNamed:@"liaotianbeijing"]];
self.tableView.backgroundView=backImageView;

2.让cell透明
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

MyCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"METext"forIndexPath:indexPath];
cell.backgroundColor=[UIColor clearColor];//关键语句
[cell setCellInfo:dic];//自定义类目方法
return cell;

}

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

推荐阅读更多精彩内容