IOS将tableview透明单元格分组

尝试使用没有任何边框的trasnparent单元格创建分组的tableview。 Tableview的背景颜色从上到下变深,变亮。

但不知何故,tableview单元格只反映背景图像的较暗部分。

我已经尝试了stackoverflow的大量答案,但它们都没有工作,无法找到解决此问题的方法。

应该是什么样子:

在此处输入图像描述

我的代码看起来像什么:

在此处输入图像描述

- (void)viewDidLoad { [super viewDidLoad]; [self.tableView setBackgroundView:nil]; self.tableView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"menu_background.png"]]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor=[UIColor clearColor]; cell.backgroundView=[[UIView alloc] initWithFrame:CGRectZero]; // UIView *backView = [[UIView alloc] initWithFrame:CGRectZero]; // backView.backgroundColor = [UIColor clearColor]; // cell.backgroundView = backView; // [[cell contentView] setBackgroundColor:[UIColor clearColor]]; // [[cell backgroundView] setBackgroundColor:[UIColor clearColor]]; // [cell setBackgroundColor:[UIColor clearColor]]; // cell.backgroundColor = [UIColor clearColor]; // cell.backgroundView.backgroundColor = [UIColor clearColor]; // cell.contentView.backgroundColor = [UIColor clearColor]; // cell.backgroundColor = [UIColor clearColor]; // UIView *bgView = [[UIView alloc] init]; // [[bgView layer] setCornerRadius:10.0f]; // [bgView setBackgroundColor:[UIColor colorWithWhite:1.0f alpha:0.25f]]; // cell.backgroundView = bgView; // return cell; } 

我错过了什么? 这是什么解决方案?

谢谢,太空

更新事实certificate,这将为分组表提供技巧:

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor clearColor]; cell.layer.backgroundColor = [UIColor clearColor].CGColor; } 

除了设置单元格的背景颜色之外,您还必须设置单元格的图层背景颜色。

ORIGINAL如果您可以使用未分组(我在您的模型中看不到任何需要分组样式的内容),则以下内容应该有效:

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor clearColor]; } 

我不知道除了伪造之外的分组解决方案,将背景分解为瓷砖并将瓷砖放入行中。 平铺式方法实际上可以在旧设备上提供更好的滚动性能。

也许你故意把它排除在外,但你是如何得到你的新细胞的呢? 它是一个定制的细胞? 假设它是标准单元格,我会尝试:

 [[cell imageView] setBackgroundColor:[UIColor clearColor]]; 

我会继续

 [cell setBackgroundColor:[UIColor clearColor]]; 

另一个想法是将它设置为白色并将alpha设置为0,所以最后很清楚,但这并不是最好的解决方案。

也许这会奏效吗? 我没有尝试重新创建测试此解决方案的问题。 如果是自定义UITableViewCell,那么我只需在xib中设置属性。

你所做的是正确的,但尝试将单元格的背景视图设置为nil以使单元格完全透明。 如果您正在使用UITableViewCell的分组tableview和单元格的子类,则通过将背景视图设置为“nil”使边框消失
cell.backgroundView = nil;

尝试这一次不确定