iOS分组的TableView透明单元格 [英] IOS grouped tableview transparent cells

查看:71
本文介绍了iOS分组的TableView透明单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试创建具有透明单元格且没有任何边界的分组表格视图. Tableview的背景颜色从上到下变暗.

Trying to create a grouped tableview with trasnparent cells without any borders. Tableview's background color from top to bottom goes darker to lighter.

但是以某种方式,tableview单元仅反映了背景图像的较暗部分.

but somehow tableview cells are only reflecting top portion of the background image which is darker.

我已经尝试了来自stackoverflow的大量答案,但是它们都没有起作用,无法找到解决该问题的方法.

I have tried tons of answers from stackoverflow but none of them is working and couldnt find the solution for this problem.

它应该是什么样的

我的代码看起来像什么

- (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;
}

我想念什么?有什么解决方案?

What am I missing ? Whats the solution for this ?

谢谢, 空间

推荐答案

更新事实证明,这将解决分组表的问题:

UPDATE Turns out, this will do the trick for grouped tables:

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

除了设置单元格的背景色之外,您还需要设置单元格的图层背景色.

You've just got to set the cell's layer background color in addition to setting the cell's background color.

原始:如果您可以使用ungrouped(我的模型中看不到任何需要分组样式的东西),则应该可以进行以下操作:

ORIGINAL If you can use ungrouped (I don't see anything in your mockup that needs grouped style), the following should work:

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

除了将背景分解成小块并将小块放在行中之外,我还没有其他针对分组的解决方案.平铺方法实际上可以在较旧的设备上提供更好的滚动性能.

I'm not aware of a solution for grouped other than faking it by breaking your background into tiles and putting the tiles in your rows. The tiled approach can actually provide much better scrolling performance on older devices.

这篇关于iOS分组的TableView透明单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆