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

时间:2013-07-20 19:59:09

标签: ios objective-c

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

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

5 个答案:

答案 0 :(得分:7)

试试这段代码:

self.view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.35]; 

答案 1 :(得分:5)

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

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

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

答案 2 :(得分:2)

您可以使用setAlpha属性根据所需的透明度指定一个介于0.0到1.0之间的浮点值,例如:

[self.tableView setAlpha:0.5];

答案 3 :(得分:1)

对于swift:

override func viewDidLoad() {

    super.viewDidLoad()
    tableView.backgroundColor = .clearColor()

}

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath){

    cell.backgroundColor = tableView.backgroundColor
    cell.contentView.backgroundColor = tableView.backgroundColor

}

答案 4 :(得分:0)

或者你可以设置背景颜色以清除颜色和alpha到一个

相关问题