TableView在View中,我如何使其透明

Iva*_*tic 9 objective-c ios

我有一个嵌入到主视图中的表视图,它是我可以使用静态表的唯一方法.主视图具有固定的背景颜色,嵌入视图不会隐藏,并且它不透明,有没有办法做到这一点?

为一个视图声明两次颜色似乎很愚蠢

Abd*_*que 7

试试这段代码:

self.view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.35]; 
Run Code Online (Sandbox Code Playgroud)

  • 你的tableViewCells也可能需要将``opaque`属性设置为`NO`和/或将`backgrounColor`设置为`[UIColor clearColor]` (3认同)

arc*_*ist 5

除了将表视图的背景颜色设置为[UIColor clearColor],您可能还需要实现此委托方法:

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

我过去必须这样做,因为细胞在返回后设置了它们的背景颜色cellForRowAtIndexPath.