esqew
esqew

Reputation: 44699

UITableViewCell contentLayer backgroundColor won't cover accessory's background

I'm writing a small application to teach myself new design and information retrieval tricks. I'm using the following line to set the background of my UITableViewCell subclass:

cell.contentView.backgroundColor = [UIColor blackColor];

... but it doesn't seem to want to get behind that accessory view:

How do I get the backgroundColor to actually span the entire background of the UITableViewCell?

Upvotes: 0

Views: 189

Answers (3)

jrturton
jrturton

Reputation: 119242

The accessory view is not added to the cell's contentView. As you can see, the content view is resized by shrinking from the right so the accessory can fit in. This also happens when the delete button is shown.

You need to set the backgroundColor of the whole cell - furthermore, this has to be done in the tableView:willDisplayCell:forRowAtIndexPath: delegate method.

Upvotes: 1

esqew
esqew

Reputation: 44699

Not exactly a definitive answer to this question, but it works well when you use the "grouped" view instead of the standard UITableView style.

Upvotes: 0

rishi
rishi

Reputation: 11839

If you want to set color of entire cell, then use -

cell.backgroundColor = [UIColor blackColor];

Upvotes: 0

Related Questions