设置 tableview 的背景 颜色 和清空

时间:2023-03-08 21:53:21
设置 tableview 的背景 颜色 和清空

表示图中Cell默认是不透明的,那么在设置表示图的背景颜色和图片时通常是看不到的

1.给tableView设置背景view

UIImageView *backImageView=[[UIImageViewalloc]initWithFrame:self.view.bounds];

[backImageView setImage:[UIImage imageNamed:@"liaotianbeijing"]];

self.tableView.backgroundView=backImageView;

[self.view addSubView: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;

}