简体   繁体   中英

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 ?

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.

如果要设置整个单元格的颜色,请使用-

cell.backgroundColor = [UIColor blackColor];

这个问题并不是确切的答案,但是当您使用“分组”视图而不是标准UITableView样式时,它会很好地工作。

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