单元格背景图像模式

Cell background image mode

我在 UITableView 中有一个单元格,使用 colorWithPatternImage 将图像作为背景。我想在此图像上设置一种模式以适合单元格,即 UIViewContentModeScaleAspectFill,等等(我会仔细研究并找到最适合我使用的模式)

这是我的代码:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath
                                                                                                      *)indexPath
{
    if((indexPath.row)==1)
        cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"homeScreen-buttons.jpg"]];

}

那么我该如何编辑我的代码来添加我需要的东西呢?谢谢

你可以设置单元格层的contents,试试这个:

cell.layer.contents = (id)[UIImage imageNamed:@"homeScreen-buttons.jpg"].CGImage;