2013-03-05 111 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. 将背景图像添加到您的手机。它肯定会显示阴影。
相关问题