设置UITableViewCell半透明效果
这两天在鼓捣leaves( https://github.com/brow/leaves ),看着那个tableview效果觉得不爽啊。想改成半透明的,搞了半天,最后发现被mainwindow.xib里的视图默认背景给害到了,我靠,默认是绿色的。。。我说怎么调alpha值都觉得不对劲呢。下面发一下改这个半透明修改的代码,高手请绕道吧,俺是新警察。
1. leaveappdelegate.m
在[window addSubview:viewController.view]; 之前加个背景,代码如下
UIImageView *cellImage = [[UIImageView alloc] init];
[cellImage setImage:[UIImage imageNamed: @"3.png"]];
cellImage.frame = CGRectMake(0, 0, 320, 480);
[window addSubview:cellImage];
2. 把mainwindow.xib的背景由绿色改为白色默认。
3. examplesviewcontroller.m
在init函数中加一句
self.tableView.backgroundColor = [UIColor clearColor];
在函数- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中, 创建完cell之后设置cell.opaque = NO; //必须的
然后再加几句:
cell.textLabel.backgroundColor = [UIColor clearColor]; //必须的
cell.backgroundColor = [UIColor colorWithRed:(247.0/255.0) green:(151.0/255.0) blue:(121.0/255.0) alpha:.3]; //设置你想要的cell背景颜色,alpha是透明度参数
设置section的高度