Altering the background color of cell.accessoryView and cell.editingAccessoryView

前端 未结 5 793
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 13:45

Whenever I add an accessoryView to my UITableViewCell, it doesn\'t carry the background color across? I\'m setting a UISwitch as my accessoryView, and the color I have set i

5条回答
  •  情深已故
    2020-12-05 13:57

    @Zak, first of all thanks for bringing to my attention the details of the cell layout. Very helpful!
    I would just like to point out that the following code:

    self.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"cell_background.png"]];
    

    worked for me. The result was a background image stretching over whole cell. AccessoryTypeView didn't cover it! Important part is to put this code into layoutSubviews method of your custom cell class and not into cellForRowAtIndexPath found in TableViewController class. In my case I defined a class CustomCell and inside of it I have defined labels, image views etc.

    NOTE:The following code wasn't working:

    cell.contentView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"cell_background.png"]];
    

    when put inside tableView:(UITableView *)tableView cellForRowAtIndexPat method. It was giving me the background covering the cell but AccessoryTypeView was above it...

提交回复
热议问题