IOS 设置TableViewCell背景透明
2015-08-17 20:56
375 查看
刚在网上看了下有些前辈关于UITableViewCell背景透明的设置方法,之后在自己的工程里面设置了下没有成功,自己找了下原因。
1.UItableViewController在实例化的时候创建了三个图层一个背景层,一个TableView层,一个cell层。如果在设置背景层上背景图片,cell想要让背景透明并且是以背景层的背景图片为背景的话,那么就需要将中间层(TableView层)的背景色设置成透明的。具体代码如下
1.在TableViewController中设置背景图片UIImageView *bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.height)];
bgImgView.image = [UIImage imageNamed:@"bg-pubthree"];
UIView * viewTemp=[[UIView alloc] initWithFrame:self.view.frame];
UITableView * tableTemp=self.tableView;
self.view=viewTemp;
[self.view addSubview:bgImgView];
[self.view addSubview:tableTemp];
2.将TableView的BackgroundColor设置成透明
UIView * view = [[UIView alloc]initWithFrame:CGRectZero];
self.tableView.backgroundColor = [UIColor clearColor];
3.设置Cell的BackgroundColor为透明
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellID = @"cell";
FGMessageCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[FGMessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 44)];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- js利用div背景,做一个竖线的效果。
- jQuery定义背景动态切换效果的方法
- 背景,文字渐变(无闪屏)
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- .net平台推送ios消息的实现方法
- 在shell或者perl中改变字体或背景的颜色
- JS修改iframe页面背景颜色的方法
- JS实现往下不断流动网页背景的方法
- js实现点击图片改变页面背景图的方法
- js点击更换背景颜色或图片的实例代码
- JavaScript让网页出现渐隐渐显背景颜色的方法
- Android设置PreferenceCategory背景颜色的方法