2012-02-22 7 views
0

J'ai appliqué une image semi-transparente à mon UITableViewCell.contentView. Chaque fois que j'ajouter mon accessoryView personnalisé, il ne dispose pas de l'arrière-plan à droite comme indiqué ici:Arrière-plan cohérent pour UITableViewCell

enter image description here

Voici le code correspondant:

UITableViewCell *tableViewCell = [[UITableViewCell alloc] init]; 
[tableViewCell.contentView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell-bg.png"]]]; 
//[tableViewCell.backgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell-bg.png"]]]; 
tableViewCell.textLabel.text = @"Test"; 

UIButton *accessoryButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[accessoryButton setBackgroundImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal]; 
[accessoryButton setFrame:CGRectMake(0, 0, 34, 34)]; 
tableViewCell.accessoryView = accessoryButton; 

J'ai aussi essayé d'ajouter l'image d'arrière-plan à backgroundView au lieu de contentView, mais il n'apparaît pas du tout. Comment résoudre ceci? Merci

Répondre

1

Dans votre caisse UITableViewCell un objet UIImage. Ajoutez-le sur votre cellule. Et puis ajoutez tous les autres objets sur l'image. Vous obtiendrez les écrans de désir de cette façon.

1

essayez ceci: -

UIImageView *imgViewCell = [[UIImageView alloc] init]; 
     [imgViewCell setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 45.0f)]; 
     [imgViewCell setImage:[UIImage imageNamed:@"list_bg"]]; 
     [imgViewCell setBackgroundColor:[UIColor clearColor]]; 
     [cellView.contentView addSubview:imgViewCell]; 
     [imgViewCell release]; 


      UILabel *nameLbl = [[UILabel alloc]initWithFrame:CGRectMake(10.0f, 2.0f, 200.0f, 40.0f)]; 

     [nameLbl setFont:[UIFont systemFontOfSize:13.0f]]; 
      [nameLbl setText:@"Test"]; 
     [nameLbl setTextColor:[UIColor blackColor]]; 
     [nameLbl setBackgroundColor:[UIColor clearColor]]; 
     [cellView.contentView addSubview:nameLbl]; 



      UIButton *accessoryButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
      [accessoryButton setImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal]; 
      [accessoryButton setFrame:CGRectMake(0, 0, 34, 34)]; 
      cellView.accessoryView = accessoryButton; 

Please use arrow.png background transparent 
Questions connexes