UITableViewCell Set Selected Image

后端 未结 5 1193
误落风尘
误落风尘 2021-02-07 08:26

trying to figure out how to set the selected image for for a tableViewCell.

The old way of writing this was cell.selectedImage but that has bee

相关标签:
5条回答
  • 2021-02-07 08:44

    According to the Deprecated UITableViewCell Methods doc, you should use the imageView's highlightedImage property as a replacement for selectedImage. For example:

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.imageView.image = [UIImage imageNamed:@"deselected_image.png"];
    cell.imageView.highlightedImage = [UIImage imageNamed:@"selected_image.png"];
    
    0 讨论(0)
  • 2021-02-07 08:47

    That didn't worked because you might set the normal state image like this

    cell.imageView.image = ///
    

    Try it - It worked for me perfectly!!

    UIImageView *selBGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"urimage_selected.png"]];
     cell.selectedBackgroundView = selBGView;
    [selBGView release];
    
    UIImageView *BGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"urimage.png"]];
     cell.backgroundView = BGView;
    [BGView release];
    
    0 讨论(0)
  • 2021-02-07 08:47

    Try this ...

        UIImage *bgImage = [UIImage imageNamed:@"icon_call.png"];
        UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
    
        [bgImageView setFrame:CGRectMake(280, 2, 30, 38)];
    
    //Finally give this imageView to the cell
    
         [cell.contentView addSubview:bgImageView];
    

    Hope it will solve your problem !

    0 讨论(0)
  • 2021-02-07 08:47

    Use this one!:

    selectionBackground = [UIImage imageNamed:@"background.png"];
    cell.selectedBackgroundView =[[UIImageView alloc] init];
    ((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
    
    0 讨论(0)
  • 2021-02-07 08:52

    You can set selected backgroundView like below....

            UIImageView *selBGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"urimage.png"]];
                    cell.selectedBackgroundView = selBGView;
    
    0 讨论(0)
提交回复
热议问题