2013-03-05 92 views
0

我有一個分組的tableview,我在每個部分有一行。我在小區的backgroundview設置爲我的自定義圖像,我希望該行被渲染的是這樣的:uitableviewcell自定義背景問題

enter image description here

但它呈現這樣的(注意沒有陰影,這是平):

enter image description here

下面是的cellForRowAtIndexPath代碼:

((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"BGImage"]; 

哪裏BGImage是在這篇文章中的第一張圖片,帶有陰影。我在這裏錯過了什麼?

回答

4

你必須設置使用的UITableView的波紋管的委託方法你的背景: -

- (void)tableView: (UITableView*)tableView 
    willDisplayCell: (UITableViewCell*)cell 
forRowAtIndexPath: (NSIndexPath*)indexPath 
{ 
      UIImage *img = [UIImage imageNamed:@"yourImage.png"]; // get your background image 
      UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img]; 
      cell.backgroundColor = backgroundColor; 
      cell.textLabel.backgroundColor = [UIColor clearColor]; 
      cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 

} 

你的問題可能是你的形象Heightwidth和你的heightwidth不相同

我上面使用方法在我的項目設置波紋管陰影圖像設置在單元格中: -

enter image description here

和它看起來像項目: -

enter image description here

+0

你是對的!除了在我的情況下,我需要cell.backgroundView設置爲包含我的圖像的圖像視圖。現在呈現良好。感謝willDisplayCell提示! – Bourne 2013-03-05 06:32:31

0
  1. 你的身影一定是你的形象的一部分。
  2. 您必須正確設置高度和寬度。
  3. 我建議你創建一個自定義UITableViewCell
  4. 將背景圖像添加到您的手機。它肯定會顯示陰影。