代码之家  ›  专栏  ›  技术社区  ›  pankaj

更改自定义单元格的背景色

  •  0
  • pankaj  · 技术社区  · 14 年前

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
        if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
    
            self.textLabel.backgroundColor = [UIColor clearColor];
            self.textLabel.textColor = [UIColor orangeColor];
            self.textLabel.text = @"lklklk";
            self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            self.contentView.backgroundColor = [UIColor blackColor];
            self.accessoryView.backgroundColor = [UIColor blackColor];
        }
    
        return self;
    
    }
    

    单元格仅显示上面背景为白色的文本

    提前谢谢

    2 回复  |  直到 11 年前
        1
  •  2
  •   Jacob Relkin    14 年前

    我在工作的时候不得不自己应付这个挑战 Spring Cleaning

    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor = [UIColor blackColor];
    view.opaque = YES;
    self.backgroundView = view;
    [view release];
    
        2
  •  0
  •   DarkDust    14 年前

    UITableViewCells有一个背景视图,您需要隐藏该视图才能设置背景颜色:

    [self.backgroundView setHidden:YES];
    self.backgroundColor = [UIColor clearColor];
    self.opaque = NO;