UITableViewCell设置选定的图像
试图找出如何设置为tableViewCell
选定的图像。
旧的写这个方法是cell.selectedImage
但是从3.0开始已经被弃用了。
我已经尝试了很多东西,但是不能太好工作。
谢谢! 玩笑
根据弃用的UITableViewCell方法文档,您应该使用imageView的HighlightImage属性作为selectedImage的替代品。 例如:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; cell.imageView.image = [UIImage imageNamed:@"deselected_image.png"]; cell.imageView.highlightedImage = [UIImage imageNamed:@"selected_image.png"];
你可以设置选定的backgroundView像下面….
UIImageView *selBGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"urimage.png"]]; cell.selectedBackgroundView = selBGView;
这没有奏效,因为你可以像这样设置正常的状态图像
cell.imageView.image = ///
试试吧 – 它对我完美的工作!
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];
尝试这个 …
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];
希望它能解决你的问题!
使用这个!:
selectionBackground = [UIImage imageNamed:@"background.png"]; cell.selectedBackgroundView =[[UIImageView alloc] init]; ((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;