我创建了一个包含多个 UIImageView 实例的 UIScrollView。SDWebImage 框架用于缓存图像并将它们呈现在 UIImageView 实例中。现在我希望能够点击这些 UIImageView 实例。
以前我将 UIButtons 添加到 UIScrollView 并在此按钮中添加了图像。但知道我无法将 UIImageView 添加到按钮。我应该如何解决这个问题?是否可以在此视图上放置 UIButton?我该怎么做?
我以前用它来添加可点击的图像(我需要改变它,由于 SDWebImage 框架,所以我不能使用 UIImage imageNamed:forState
CGFloat y = i * self.view.frame.size.height/6;
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setTag:[[idsCol objectAtIndex: i] intValue]];
aButton.frame = CGRectMake(0, y, self.view.frame.size.width/3, self.view.frame.size.height/6);
aButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
[aButton setImage:[UIImage imageNamed:@"image.jpg" forState:UIControlStateNormal];
[aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
aButton.adjustsImageWhenHighlighted = NO;
[scrollView addSubview:aButton];
我目前需要使以下图像视图可点击:
[testImageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];