我们可以像UITableViewCell backGroundView一样为UITableView部分设置背景图像.根据我的研究,它是不可能的&我们需要自定义行的部分.
除此之外,我们能够获得更好的解决方案.
提前致谢!
最佳答案 如果有人仍然感兴趣,实际上有一个相当直接的解决方案. UITableView将使用选择器rectForSection告诉您每个部分的帧:
将背景图像添加到每个部分将看起来像这样(视图控制器中的某处):
for(int i = 0;i < [self numberOfSectionsInTableView:self.tableView]; i++) {
UIImage *img = [[UIImage imageNamed:@"background"] resizableImageWithCapInsets:UIEdgeInsetsMake(30.0, 30.0, 40.0, 40.0) ]; //In this example the image is stretchable
UIView *borderView = [[UIImageView alloc] initWithImage:img];
CGRect section_rect = [self.tableView rectForSection:i];
borderView.frame = section_rect;
[self.tableView addSubview:borderView];
}
请记住,如果您在tableview中重新加载数据,则还必须重做此操作.