iOS 7 UItableview单元格背景视图

我使用图像视图作为tableview单元格背景视图。 当我在xcode 4.x中编译我的源代码时,它工作正常,即,在iOS 6.x和7.0中,它工作正常。 但是当我在xcode 5.0中编译源代码时,背景图像视图没有出现在iOS 7中。

任何想法,为什么它不起作用? 在iOS 7中对uitableview单元格背景视图有任何限制吗?

if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:accountProfileTypeCell]; UIImageView *cellBgView =[[UIImageView alloc]init]; [cellBgView setImage:[UIImage imageNamed:@"cellBgView.png"]]; [cell setBackgroundView:cellBgView]; } 

尝试添加:cell.backgroundColor = [UIColor clearColor];

您必须在willDisplayCell中设置背景。 下面的代码与你的相同,只是在willDisplay方法中移动它

 -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ if(cell.backgroundView==nil){ UIImageView *cellBgView =[[UIImageView alloc]init]; [cellBgView setImage:[UIImage imageNamed:@"cellBgView.png"]]; [cell setBackgroundView:cellBgView]; } } 

尝试这个。 这对我有用

  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:accountProfileTypeCell]; UIView *cellBgView =[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [cell frame].size.width, [cell frame].size.height)]; [cellBgView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBgView.png"]]]; [cell setBackgroundView:cellBgView]; 

唯一缺少的是将帧设置为cellBgView。 将图像设置为它不会调整imageView的大小。 但是,如果使用initWithImage:初始化imageView,它将调整imageView的大小以适合图像。

您只需要在imageview中应用自动resize。

如果您的imageview应用于整个屏幕。 为其分配所有边距。

检查图像

设置自动调整视图以使其与iOS6和iOS7兼容