Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe to Delete in UITableViewCell has white background, need clear

I am trying to change the background color of the view that appears when you swipe a UITableViewCell row, the background color behind the 'Delete' button.

I tried changing the cell.editingAccessoryView but that didn't do anything.

    UIView* myBackgroundView = [[UIView alloc] initWithFrame:CGRectZero];
    myBackgroundView.backgroundColor = [UIColor clearColor];
    cell.editingAccessoryView = myBackgroundView;

Any ideas?

like image 292
mootymoots Avatar asked Jan 01 '12 22:01

mootymoots


2 Answers

I'm answering this because it took me a while to find an answer and this is the first entry that comes up in a search. By using the willDisplayCell method you can access the cells background color. Note that [UIColor clearColor]; will return white in so adjust your code accordingly.

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

    cell.backgroundColor = [UIColor blackColor];

}
like image 185
justMike Avatar answered Oct 05 '22 23:10

justMike


You're almost there. The UITableViewCell class has a backgroundView property, which is nil by default. Just create a new UIView as you've done in your question, then assign that to the backgroundView property of your cell.

cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cell.backgroundView.backgroundColor = [UIColor clearColor];
like image 27
Arash Payan Avatar answered Oct 05 '22 23:10

Arash Payan