Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" (i.e., 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?

like image 855
Matt Avatar asked Jun 01 '11 21:06

Matt


People also ask

How do I change the background color on my view controller?

First let us see using storyboard, Open Main. storyboard and add one view to the View Controller. On the right pane you can see the property, and from there update the background color to color you want your view to be as show below.

How do I change the background color in Xcode?

At the top select the attributes inspector. Under the section "View" there should be a spot that says "Background". click that and choose your colour.


1 Answers

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.

like image 83
Matt Avatar answered Oct 12 '22 23:10

Matt