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

前端 未结 14 1769
青春惊慌失措
青春惊慌失措 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 12:08

    This is simple and works: in interface builder, add a view object to the UITableViewCell of the same dimensions, and place your controls inside that view. Then you get whatever background color you want.

    Edit: here's a reason to accept, it just struck me: take a careful look at what you get when you double click on a UITableViewCell in IB that you place into your nib, to start adding stuff to it: you don't get a plain rectangle looking view, you get an oval rectangle that says quite clearly: Content View. So all you can do is set the content view of the UITableViewCell in IB, and setting the background color property of the content view does not produce the color change in the table. As the docs say, UITableViewCells are complex beasts with many parts with a lot going on behind the scenes in terms of the UITableView adjusting it and fiddling with it.

    0 讨论(0)
  • 2020-12-23 12:10
    [cell.textLabel setBackgroundColor:[UIColor clearColor]];
    [cell.contentView setBackgroundColor:[UIColor redColor]];
    
    0 讨论(0)
提交回复
热议问题