用于分组的UITableView的半透明UITableViewCell? [英] Translucent UITableViewCell for grouped UITableView?

查看:55
本文介绍了用于分组的UITableView的半透明UITableViewCell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个TRANSLUCENT分组表视图单元格.换句话说,我想查看分组的表格视图背景图案,但我不希望完全清除单元格.我已经看到很多有关透明单元格的问题,但是没有一个问题解决了使半透明(仅部分透明)单元格的问题.

I would like to create a TRANSLUCENT grouped table view cell. In other words I want to see the grouped table view background pattern, but i don't want completely clear cells. I've seen a lot of questions about transparent cells but none address making translucent (only partially transparent) cells.

这是我正在尝试的:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.contentView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:0.5f];
    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView.backgroundColor = [UIColor clearColor];
}

这是结果:

几乎是正确的,只是单元格的contentView超出了分组单元格的圆角.

It's almost right, except that the contentView of the cell extends beyond the rounded corners of the grouped cell.

已解决,方法是使用透明图像并设置单元格的背景视图.不过,本来还是想通过编程来完成它,所以如果有人有解决方案,我将很乐意接受.

SOLVED by using a transparent image and setting the cell's background view. Would have still liked to do it programmatically though, so if anyone has a solution, I will gladly accept it.

已解决的第二部分,也可以通过将quartzView设置为新的UIView来完成,该UIView通过QuartzCore对视图图层属性的setCornerRadius调用,具有所需的背景颜色和圆角.

SOLVED Part II Can also be done by setting backgroundView to a new UIView, that has the desired background color and rounded corners via QuartzCore's setCornerRadius call to the view's layer property.

推荐答案

对于任何其他想知道的人,我最终使用的代码是:

For anyone else wondering, the code that I ended up using was:

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    //...  

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

这篇关于用于分组的UITableView的半透明UITableViewCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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