Iphone 如何在表格视图单元格上设置高亮显示的图像?
我遵循苹果的代码,构建了一个带有单元格背景图像的表格视图。现在我想改变它,让它显示我的图像的较暗版本,而不是蓝色高亮颜色。要做到这一点,我需要遵循哪些步骤?我正在使用带有自定义NIB的Iphone 如何在表格视图单元格上设置高亮显示的图像?,iphone,cocoa-touch,image,uitableview,Iphone,Cocoa Touch,Image,Uitableview,我遵循苹果的代码,构建了一个带有单元格背景图像的表格视图。现在我想改变它,让它显示我的图像的较暗版本,而不是蓝色高亮颜色。要做到这一点,我需要遵循哪些步骤?我正在使用带有自定义NIB的UITableViewCell子类。我的背景图像实现为单元格。backgroundView 到目前为止,我采取的步骤是: 将单元格的selectionStyle更改为“无” 将myUILabel子视图上的突出显示颜色设置为浅色 创建一个较暗的背景作为一个单独的图像 覆盖setSelected:已设置动画: 我想
UITableViewCell
子类。我的背景图像实现为单元格。backgroundView
到目前为止,我采取的步骤是:
- 将单元格的
更改为“无”selectionStyle
- 将my
子视图上的突出显示颜色设置为浅色UILabel
- 创建一个较暗的背景作为一个单独的图像
- 覆盖
setSelected:已设置动画:
我想知道接下来的步骤。是否尝试替换
setSelected:animated:
中的图像
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if (selected) {
// replace image here
// or move a pointer from one image to another
}
}
我找到了
selectedBackgroundView
属性。我使用的是这种方法,而不是setSelected:animated:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:@"TableBackground" ofType:@"png"];
UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundImagePath];
self.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
self.backgroundView.frame = self.bounds;
NSString *selectedBackgroundImagePath = [[NSBundle mainBundle] pathForResource:@"TableBackgroundDark" ofType:@"png"];
UIImage *selectedBackgroundImage = [UIImage imageWithContentsOfFile:selectedBackgroundImagePath];
self.selectedBackgroundView = [[[UIImageView alloc] initWithImage:selectedBackgroundImage] autorelease];
self.selectedBackgroundView.frame = self.bounds;
return self;
}
我不确定这是否是正确的方法,因为它引入了一些其他问题。有一点是,单元格
selectionStyle
必须是uitableviewCellSelectionstyle以外的内容,否则它不会显示背景图像。取消选择动画也已停止工作。关于这些问题,我将提出一个新问题。谢谢你的回答。这是我一直在尝试的,但我必须手动处理取消选择。