半透明的UITableViewCell分组的UITableView?

我想创build一个TRANSLUCENT分组表格视图单元格。 换句话说,我希望看到分组表查看背景图案,但我不想完全清除细胞。 我已经看到了很多关于透明单元的问题,但没有提到半透明单元(只有部分透明)。

这就是我想要的:

- (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超出了分组单元格的圆angular之外。

通过使用透明图像解决 ,并设置单元格的背景视图。 本来仍然喜欢以编程的方式来做,所以如果有人有解决scheme,我会很乐意接受它。

已解决的第二部分也可以通过设置backgroundView到一个新的UIView,具有所需的背景颜色和圆angular通过QuartzCore的setCornerRadius调用视图的图层属性。

这应该是你需要的一切:

 cell.contentView.backgroundColor = [UIColor clearColor]; cell.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.5]; 

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

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