2011-10-14 4 views
0

Quelle est maintenant la bonne façon de définir l'image d'arrière-plan pour les états normaux et sélectionnés de UITableViewCell? En XCode 4, je le faisais dans l'IB mais maintenant ces options ne sont pas disponibles.Xcode 4.2 Fond UITableViewCell

+0

Cela aide-t-il? : http://stackoverflow.com/questions/894875/how-can-i-set-the-background-of-favorable-the-tableview-style-is-grouped-to – trojanfoe

+0

Il parle de la uitableview - pas la cellule . Je me demandais à propos de la récente modification de xcode qu'il n'y a pas de place pour choisir l'image de fond dans l'IB. – bolshas

Répondre

2

J'ai fini par régler la cell.backgroundView:

  UIView *backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
      backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_background.png"]]; 
      cell.backgroundView = backgroundView; 

Pour l'état sélectionné j'ai utilisé la sélection bleue par défaut.

+0

Appelez-vous ce code dans cellForRowAtIndexPath? – bolshas

+0

Oui. Collez-le dans if (cell == nil) –

0
UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource: @"image_name" ofType:@"png"]]; 

UIImageView *av = [[UIImageView alloc] initWithImage:bgImage]; 

cell.backgroundView = av; 
+0

Pourriez-vous ajouter quelques explications? – Undo