iOS5将蓝色单元格选择更改为自定义图像渐变而不进行子类化

时间:2012-05-02 23:05:23

标签: ios ios5 uikit

所以在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;
}

1 个答案:

答案 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;
}