IOS 分组 TableView 透明单元格

标签 ios uitableview

尝试使用没有任何边框的透明单元格创建分组表格 View 。 Tableview 的背景颜色从上到下由深到浅。

但不知何故,tableview 单元格只反射(reflect)了背景图像的顶部较暗的部分。

我已经尝试了来自 stackoverflow 的大量答案,但没有一个有效,也找不到解决此问题的方法。

它应该是什么样子:

enter image description here

我的代码看起来像什么:

enter image description here

- (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/

相关文章:

ios - 如何通过 UICollectionViewController (Swift) 中的 didSelectItemAtIndexPath() 方法访问所有单元格

ios - 如何制作图像可调整大小的裁剪框

iphone - 单击 TableView 会将您带到另一个 View

ios - swift - 无需重新加载自定义 UITableViewCell 即可设置 UILabel

ios - 如何自定义UITableView包含多行,每行包含多个子行?

ios - iAd 和 AdMob 占用大量内存

ios - 我在 TabBarController 中有 4 个 ViewController。当 TabBarController 被解除分配时,只有 3 个被解除分配。为什么?

ios - 如何使用动态单元格获取 UITableView 中多个文本字段的值?

ios - 如何编写面向协议(protocol)的部分

ios - 当我动态更改其框架时,即使重新加载后 UITableView 内容大小也不会更新