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

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

    It works perfectly, if you pick the tableview and set background to for example red the whole table will be red. maybe you do not linked the table or something

    hope it helped

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

    Trying to set the background colour of the UITableViewCell itself is not how you should be doing it. A table cell has a collection of five useful views you can access, one of which is backgroundView.

    Recommended reading:

    http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

    and then:

    http://cocoawithlove.com/2010/12/uitableview-construction-drawing-and.html

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

    (try this)

    Apple's IB's design is generic to be applied to multiple kinds of components, and is also targeted at a highly technical audience (developers). Hence it has not been designed (as an application) to fully customise the interface properly for each component/situation type. So in this case it is the case the ability to seemingly set the background-color is somewhat misleading.

    0 讨论(0)
  • 2020-12-23 12:00

    What worked for me is creating my own UIView object to be set as the background view of the UITableViewCell. In the cellForRowAtIndexPath:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
    bgview.opaque = YES;
    bgview.backgroundColor = [UIColor orangeColor];
    [cell setBackgroundView:bgview];
    
    0 讨论(0)
  • 2020-12-23 12:04

    It's a bit late, but I just ran into this issue... Setting the background color on the contentView works fine:

    cell.contentView.backgroundColor = [UIColor redColor];
    
    0 讨论(0)
  • 2020-12-23 12:04

    Try this it works for me:

    - (void)tableView:(UITableView *)tableView1 willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [cell setBackgroundColor:[UIColor clearColor]];
        tableView1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"Cream.jpg"]];
    }
    
    0 讨论(0)
提交回复
热议问题