您可以通过 indexPath.row 变量计算每一行的部分大小。之后,使用您计算的 CGRect 值裁剪图像。
CGFloat top = (indexPath.row == 0) ? 0 : (indexPath.row * 44) + 1;
CGRectMake(0, top, 320, 44);
是你裁剪图像的矩形吗
您可以使用此答案来裁剪 UIImage。
操作编辑:谢谢!添加我从建议中得出的结论:
UIImage *image = [UIImage imageNamed:@"custombackground.png"];
CGFloat y = indexPath.row * 44;
for (y; y+44 > image.size.height; y -= image.size.height);
//Sends our y origin back to the top of the image in case
//the image would have ended in the middle of a cell, so
//it can be used for any length of table.
CGRect cropRect = CGRectMake(0, y, 320, 44);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithCGImage:imageRef]];