簡體   English   中英

UITableViewCell 清除背景 - 分組 UITableView

[英]UITableViewCell clear background - Grouped UITableView

我正在嘗試在分組表中顯示我的數據,如下所示:

在此處輸入圖像描述

如您所見,我通過在viewDidLoad中編寫以下代碼清除了表格的背景視圖:

customerTable.backgroundView = nil;  

同樣在我的xib中,我已經清除了我的桌子的背景。

cellForRowAtIndexPath中,我為每個表格單元格設置了背景顏色。

cell.backgroundColor = [UIColor colorWithRed:255.0/255 green:235.0/255 blue:178.0/255 alpha:1];  

結果,我得到了上面的 output。

我面臨的問題是我在每個單元格中都遇到了黑角 我知道這與細胞的背景有關,但對我沒有任何作用。 我還嘗試清除單元格的背景編寫以下代碼行:

    cell.backgroundView = nil;  

嘗試

customerTable.backgroundColor = [UIColor clearColor];
customerTable.opaque = NO;
customerTable.backgroundView = nil;

我面臨着同樣的問題。 並且知道它與細胞的背景無關。

問題在於 tableview 的背景導致了這個奇怪的角落,所以

self.tableview.backgroundColor = [UIColor clearColor];

viewWillAppear將解決問題:)

在 cellForRowAtIndex 方法中清除背景應該可以工作

[cell setBackgroundColor:[UIColor clearColor]];

還嘗試清除 viewWillAppear 中的背景,如果發生奇怪的事情,請清除項目並重建。

試試這個代碼......

customerTable.separatorColor = [UIColor clearColor];

嘗試

- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath

{

  cell.backgroundColor = [UIColor clearColor];

}

試試吧:

將單元格背景視圖設置為 YourcellImage & 單元格背景顏色以清除顏色。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath             
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

        [cell setBackgroundColor:[UIColor clearColor]];
        UIImage *backgroundImage = nil;
        UIImageView *backgroundView = nil;
        backgroundImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"YourYellowCellImage"ofType:@"png"]];
        backgroundView = [[UIImageView alloc]initWithImage:backgroundImage];
        backgroundView.frame = CGRectMake(0, 0, 600, 80); // Over here give your cell size
        cell.backgroundColor = [UIColor clearColor];
        cell.backgroundView =backgroundView;

        [backgroundView release];   
   }
   //Over your set your Label Value    
   return cell;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM