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

uiTableViewCell阻塞背景中的标签

  •  3
  • rob5408  · 技术社区  · 14 年前

    我的标签有问题 UITableViewCell 阻止背景图像。似乎它只发生在未选择的状态。我试着将背景色设置为清晰,但没有做到。它采用了TableView的背景色。我也必须设置标签背景图像吗?

    // Neither of these worked...
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.contentView.backgroundColor = [UIColor clearColor];
    

    screen shot

    这是我的 cellForRowAtIndexPath

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableIdentifier"];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"SimpleTableIdentifier"] autorelease];
        }
    
        UIImage *image = [UIImage imageNamed:@"TableRow.png"];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.contentMode = UIViewContentModeScaleToFill;
        cell.backgroundView = imageView;
        [imageView release];
    
        UIImage *imageSelected = [UIImage imageNamed:@"TableRowSelected.png"];
        UIImageView *imageViewSelected = [[UIImageView alloc] initWithImage:imageSelected];
        imageViewSelected.contentMode = UIViewContentModeScaleToFill;
        cell.selectedBackgroundView = imageViewSelected;
        [imageViewSelected release];
    
    
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.text = [[self.trivia.questionsets objectAtIndex:indexPath.row] valueForKeyPath:@"title"];
    
        return cell;
    }
    

    更新 :有点解决了……

    如果我将表的背景色(我假设它位于所有内容的下面)设置为清除,那么突然间,我的图像显示了我所期望的位置,但表的背景现在显示在所有内容的顶部?这是预期的行为吗?(还没有检查文档)

    tableView.backgroundColor = [UIColor redColor];
    cell.contentView.backgroundColor = [UIColor orangeColor];
    cell.textLabel.backgroundColor = [UIColor yellowColor];
    

    screen shot 2

    …最后,如果我将表格和单元格的背景色都设置为“清除”,我们就很好了。textLabel背景色没有区别。

    tableView.backgroundColor = [UIColor clearColor];
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.textLabel.backgroundColor = [UIColor yellowColor];
    

    screen shot 3

    1 回复  |  直到 9 年前
        1
  •  0
  •   Malaxeur    14 年前

    是的,这是预期行为。

    您的TableView是一个子视图,它位于所有其他视图的前面。如果有什么东西在桌面视图前面(即背景),它会模糊桌子。