2017-05-25 37 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];