开发者

Maintain UITableViewCell background color when going into edit mode

开发者 https://www.devze.com 2023-03-22 19:12 出处:网络
I have set background colors for all my UITableViewCells. However, when I click my UIBarBut开发者_如何学运维tonItem \"edit\", the delete and the draggable icons distort the background color, making wh

I have set background colors for all my UITableViewCells. However, when I click my UIBarBut开发者_如何学运维tonItem "edit", the delete and the draggable icons distort the background color, making white background behind them. Is there any way around this? I can show code if necessary, but this seems like a pretty straightforward question.


The background color of a table cell is usually set like this:

cell.backgroundView.backgroundColor = [UIColor redColor];

This works fine. However, when an object of class UITableViewCell is created, by default it does not have a backgroundView, it is nil. The developer needs to create the backgroundView when needed. So depending on the particular situation you need to do something like:

if (cell.backgroundView == nil) {
  cell.backgroundView = [[[UIView alloc] init] autorelease];
}
cell.backgroundView.backgroundColor = [UIColor redColor];


This is the default behavior of the uitableviewcells in the editing mode. Try setting the background color for your tableViewCells again in

 - (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
if(editing)
{
  // set background color
}

else {
}

If needed, try setting your background color as your property so that you can set it up here.

0

精彩评论

暂无评论...
验证码 换一张
取 消