尝试使用没有任何边框的透明单元格创建分组表格 View 。 Tableview 的背景颜色从上到下由深到浅。
但不知何故,tableview 单元格只反射(reflect)了背景图像的顶部较暗的部分。
我已经尝试了来自 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;
}
我错过了什么?解决方案是什么?
谢谢, 空间
最佳答案
UPDATE 事实证明,这对分组表格有用:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
cell.layer.backgroundColor = [UIColor clearColor].CGColor;
}
除了设置单元格的背景颜色外,您还需要设置单元格的图层背景颜色。
原始 如果您可以使用未分组(我在您的模型中没有看到任何需要分组样式的东西),则以下应该有效:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
}
除了通过将您的背景分解成瓷砖并将瓷砖放在您的行中来伪造它之外,我不知道分组的解决方案。平铺方法实际上可以在旧设备上提供更好的滚动性能。
关于IOS 分组 TableView 透明单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17506533/