UITableViewCell show white background and cannot be modified on iOS7

后端 未结 14 1288
轻奢々
轻奢々 2020-11-28 18:42

I\'ve implemented a custom table view cell class that inherit from UITableViewCell. The tableview contains a background image, so I want cell\'s background to b

相关标签:
14条回答
  • 2020-11-28 19:08

    I actually found that the issue arose from the UITableView's Background color not being set to clear. If you change the UITableViewCell's Background color to clear and you are finding you still see white, make sure that the UITableView's background color is set to clear (or whatever you want).

    [self.tableView setBackgroundView:nil];
    [self.tableView setBackgroundColor:[UIColor clearColor]];
    

    In Swift

    tableView.backgroundView = nil
    tableView.backgroundColor = UIColor.clearColor()
    
    0 讨论(0)
  • 2020-11-28 19:08

    It could be that your UITableViewCell is selected by default.. You can confirm this using Xcode 6s new visual debugger (or find out exactly which view is causing this white cell to appear).

    enter image description here

    Interestingly, after knowing this.. setting the background color of the selected cell to clear still didn't work.. doing some more research, turns out i just had to modify the selection style when i'm creating this custom cell:

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            // do customization here
        }
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setBackgroundColor:[UIColor clearColor]];
        return self;
    }
    
    0 讨论(0)
提交回复
热议问题