简体   繁体   中英

UITableViewCell clear background - Grouped UITableView

I am trying to display my data in a grouped table as below:

在此处输入图像描述

As you can see I have cleared the background view for the table by writing the following code in viewDidLoad :

customerTable.backgroundView = nil;  

Also in my xib I have cleared the background of my table.

In cellForRowAtIndexPath I have set the background color for each table cell.

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

As a result I am getting the above output.

The problem I am facing is the black corners I am getting in every cell. I know it has something to do with background of the cell but nothing is working for me. I also tried to clear the background of cell writing the following code line:

    cell.backgroundView = nil;  

Try

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

I was facing the same problem. And got to know It has nothing to do with cell's background.

The issue is with background of the tableview which causes this weird corners, So

self.tableview.backgroundColor = [UIColor clearColor];

in viewWillAppear will solve the issue:)

Clearing the background in the cellForRowAtIndex method should work

[cell setBackgroundColor:[UIColor clearColor]];

try also to clear the background in the viewWillAppear and if something weird happens, clear the project and rebuild.

Try this code.....

customerTable.separatorColor = [UIColor clearColor];

Try

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

{

  cell.backgroundColor = [UIColor clearColor];

}

Just try with it:

Set the cell background view to YourcellImage & cells background color to clear color.

- (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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM