所以在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;
}
答案 0 :(得分:1)
该死。发帖后30秒就想到了一件事。离开它,以防它帮助其他人。我的imageView上没有框架。工作代码:
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.frame = cell.frame;
imageView.contentMode = UIViewContentModeScaleToFill;
cell.selectedBackgroundView = imageView;
}