Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在表格视图单元格上设置高亮显示的图像?_Iphone_Cocoa Touch_Image_Uitableview - Fatal编程技术网

Iphone 如何在表格视图单元格上设置高亮显示的图像?

Iphone 如何在表格视图单元格上设置高亮显示的图像?,iphone,cocoa-touch,image,uitableview,Iphone,Cocoa Touch,Image,Uitableview,我遵循苹果的代码,构建了一个带有单元格背景图像的表格视图。现在我想改变它,让它显示我的图像的较暗版本,而不是蓝色高亮颜色。要做到这一点,我需要遵循哪些步骤?我正在使用带有自定义NIB的UITableViewCell子类。我的背景图像实现为单元格。backgroundView 到目前为止,我采取的步骤是: 将单元格的selectionStyle更改为“无” 将myUILabel子视图上的突出显示颜色设置为浅色 创建一个较暗的背景作为一个单独的图像 覆盖setSelected:已设置动画: 我想

我遵循苹果的代码,构建了一个带有单元格背景图像的表格视图。现在我想改变它,让它显示我的图像的较暗版本,而不是蓝色高亮颜色。要做到这一点,我需要遵循哪些步骤?我正在使用带有自定义NIB的
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以外的内容,否则它不会显示背景图像。取消选择动画也已停止工作。关于这些问题,我将提出一个新问题。

谢谢你的回答。这是我一直在尝试的,但我必须手动处理取消选择。