2017-05-25 41 views
0

在我的TableView中,我使用静态单元格。我拿一节,在本节中有五个单元格(静态单元格)。现在我想让整个部分或这五个单元透明。这意味着我可以通过单元格看到Table View Controller背景。我怎样才能做到这一点?TableViewController中的透明部分

我已经经历了许多解决方案。但没有解决。

编辑:

可能你们中许多人并不清楚我的问题。我想要像下面的图像单元格。它是下载的图像,并且会有该图像中不可用的部分。我只是使用这个图像来清除问题。看看单元格背景透明的图像。

enter image description here

回答

2

要以最简单的方式实现这一目标: enter image description here

在故事板选择要显示为透明的静态细胞,然后选择“组表视图背景色”或R235的背景颜色, G235,B241。

enter image description here

然后由通过设置下面设置移动其关闭屏幕移动分离器(在之间的线)。 enter image description here

如果仍要行忽略上面,或者如果你想改变它的颜色使用

override func viewDidLoad() { 
      super.viewDidLoad() 
tableView.separatorColor = //ADD COLOR HERE 
} 

然后像平时为我添加了标签和UIImage的,你可以将内容添加到这些细胞以上视图。

!!但是,实现这一点的简单但最好的方法是创建自定义单元格并使用动态原型。你可以在网上找到许多关于如何做这个的教程。

0

你有清晰的彩色细胞的内容查看,也给tableview中的细胞,现在我认为你将能够看到的背景和现在检查

+0

你能提供一些代码举例吗? – sazid008

+0

你有没有采取原型细胞? –

+0

如果你已经采用了prototypecell,那么只需去属性检查器,并在单元的内容视图中选择清除背景颜色的颜色,以及tableview单元不需要编写代码,为什么在此之后浪费代码和时间。如果你还没有这样写 cell.contentView.backgroundColor = [UIColor clearColor]; cell.backgroundColor = [UIColor clearColor]; –

0

只需添加以下代码实现代码如下

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return 10; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *headerView = [[UIView alloc] init]; 
    headerView.backgroundColor = [UIColor clearColor]; 
    return headerView; 
} 
0

覆盖您TableViewCellawakeFromNib来设置它自己的背景颜色和它的内容查看的背景色clearColor

class MyTableViewCell: UITableViewCell { 

    override func awakeFromNib() { 

     super.awakeFromNib() 
     self.backgroundColor = .clear    
     self.contentView.backgroundColor = .clear 

    } 
} 
0

你需要设置清晰的背景颜色tableView。另外tableView cell和contentView backGround颜色为透明颜色。

为此,请在viewDidLoad方法中添加此行。

[self.tableView setBackgroundView:nil]; 
[self.tableView setBackgroundColor:[UIColor clearColor]]; 

将此行添加到cellForRowAtIndexPath方法中。

cell.backgroundColor=[UIColor clearColor]; 
cell.contentView.backgroundColor=[UIColor clearColor];