简体   繁体   中英

Set background color of the deletion control of a UITableViewCell

In an iPhone/iPad app, I'm using a UITableView to display a list of items that can be edited. I can successfully alternate the background color of the rows in my table view. However, when I turn on "editing mode" (ie, display the deletion control), each cell appears to be shifted to the right, and the deletion control slides in from the left.

My problem is that the deletion control has a white background color. I'd like the background color of the deletion control to match the background color of my UITableViewCell.

How do I accomplish this?

One answer is to, in the getCellContentView function, where you create frames/labels and add them as subviews, add an additional label that is much wider and starts with a negative X value. Then, this can be colored. Since it's drawn "underneath" the deletion control, the color shows through.

The trick is to understanding that the deletion control isn't drawing "white" anywhere. The deletion control itself's background color is already clear, so you have to fit something underneath. Negative "x" value does the trick.

Try setting the background of the accessoryView which houses the delete button to UIColor clearColor . I'm not sure the exact syntax, but something like:

[tableView.editingAccessoryView setBackgroundColor:[UIColor clearColor]];

If that doesn't do it for you, you may try setting the background of the entire tableview to clear. This should not affect your customized colors for each cell.

Try this, it must help:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor clearColor];
}

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