2012-02-22 82 views
0

我已將一個半透明圖像應用於我的UITableViewCell.contentView。每當我添加我的自定義accessoryView的,它不具備正確的背景如下所示:UITableViewCell的一致背景

enter image description here

這是相關代碼:

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; 

我也嘗試添加背景圖片到backgroundView而不是contentView,但它根本不顯示。如何解決這個問題?謝謝

回答

1

在你的UITableViewCell箱子裏的一個UIImage對象。將它添加到您的手機上。然後在圖像上添加所有其他對象。你會以這種方式獲得願望屏幕。

1

試試這個: -

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