所以在一个UITableViewCell
子类中这很好用:
- (void)awakeFromNib {
[super awakeFromNib];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"table-highlight.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]];
imageView.contentMode = UIViewContentModeScaleToFill;
self.selectedBackgroundView = imageView;
}
但是,我有一个 tableView,它只使用没有子类的标准表格单元格。我已经尝试了在其他答案中找到的各种组合,但没有运气:
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"table-highlight.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]];
imageView.contentMode = UIViewContentModeScaleToFill;
cell.selectedBackgroundView = imageView;
}