2009-10-01 11 views
10

Cuando me puse los UITableViewCells backgroundColor a un color semitransparente, se ve bien, pero el color no cubre toda la célula.UITableViewCell fondo transparente (incluyendo imageView/accessoryView)

El área alrededor de la imageView y accessoryView están subiendo como [UIColor clearColor] ...

alt text

He tratado de establecer explícitamente la cell.accessoryView.backgroundColor y cell.imageView.backgroundColor ser del mismo color que la célula de backgroundColor, pero no funciona Coloca una pequeña caja alrededor del icono, pero no se expande para llenar el borde izquierdo. El borde derecho no se ve afectado por esto.

¿Cómo puedo solucionar esto?

EDITAR: Aquí está el código celda de la tabla en bruto:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     cell.opaque = NO; 
     cell.textLabel.backgroundColor = [UIColor clearColor]; 
     cell.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:.4]; 
     cell.textColor = [UIColor whiteColor]; 
    } 

    cell.imageView.image = [icons objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [items objectAtIndex:indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 

Respuesta

16

Ben y yo cuenta de esto hoy, aquí está el resumen para el grupo en caso de que las capturas de cualquier otra persona.

tiene que configurar el fondo de la celda y cell.textLabel.backgroundColor cada vez que cellForRowAtIndexPath se llama, no sólo durante la fase alloc/init (es decir, si el tableView tiene un error de caché quitar de la cola).

Por lo tanto, el código se convierte en esto:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     cell.opaque = NO;   
    } 

    // All bgColor configuration moves here 
    cell.textLabel.backgroundColor = [UIColor clearColor]; 
    cell.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:.4]; 
    cell.textColor = [UIColor whiteColor]; 
    cell.imageView.image = [icons objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [items objectAtIndex:indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 
+1

en realidad tenía que hacer 1 cosa más. El cell.textLabel.backgroundColor necesario para ajustarse * después * de color de fondo de la celda. No tengo idea de por qué tengo que hacer esto, pero ahora está funcionando. Gracias Mike! –

2

¿Ha mirado en establecer el color de fondo de la celda de contentView y mantener la célula, accesorio, y vistas de imágenes transparente?

Además, this article podría ayudarle a mostrar algunas alternativas.

+0

que estaba usando ese artículo para la inspiración, pero desafortunadamente él no utiliza células transparentes. Ajuste del color de fondo contentView tuvieron efectos muy extraños. También intenté configurar contentView.opaque = NO, pero aún parecía horrible. –