Why doesn't UITableViewCell background color work (set in interface builder)?

前端 未结 14 1767
青春惊慌失措
青春惊慌失措 2020-12-23 11:43

Why doesn\'t UITableViewCell background color work (set in interface builder)?

I note from some searching that the follow code set in your custom subclass of UITable

相关标签:
14条回答
  • 2020-12-23 11:44

    Y not, use setBackgroundColor

    self.table.separatorColor=[UIColor whiteColor];
    [table setBackgroundColor:[UIColor colorWithRed:.8 green:.8 blue:1 alpha:1]];
    
    0 讨论(0)
  • 2020-12-23 11:49

    I did get this issue also. In IB you get the ability to change the background color of the cell when choosing cell. This is NOT correct. You should go to the document outline on the left of the storyboard and choose the content view inside the cell. Change the background of the content view. You should now get correct cell color.

    0 讨论(0)
  • 2020-12-23 11:50

    You should always provide changes for cells in tableView:willDisplayCell:forRowAtIndexPath: instead of the tableView:cellForRowAtIndexPath: method, as per Apple Documentation.

    This Works !!

    0 讨论(0)
  • 2020-12-23 11:53

    You can partially do this in Interface Builder (probably added to Xcode recently):

    • Expand the cell in the Storyboard's Document Outline and select "Content View"
    • Set Content View background color in the Attributes Inspector
    • Select each content item in the cell and set their background colors to ClearColor

    Still don't see a way to set the accessory background though.

    0 讨论(0)
  • 2020-12-23 11:56
    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    UIView *view = [[UIView alloc] init];
    [view setBackgroundColor:[UIColor redColor]];
    [cell setSelectedBackgroundView:view];}
    

    We need to change the color in this method.

    0 讨论(0)
  • 2020-12-23 11:57

    Make sure before defining a cell color your backgroundView is null

    cell.backgroundView = nil;
    cell.backgroundColor = [UIColor redColor];
    
    0 讨论(0)
提交回复
热议问题