我正在创建一个包含图像的水平滚动表格视图。我的滑动功能运行良好,并且能够将图像添加到scrollView
如下所示cellForRowAtIndexPath
:
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 78)];
[scrollView setContentSize:CGSizeMake(700, 78)];
UIImage *footImage = [UIImage imageNamed:@"Foot.png"];
UIImageView *footImageView = [[UIImageView alloc] initWithImage:footImage];
footImageView.frame = CGRectMake(0, 0, 80, 78);
footImageView.userInteractionEnabled = YES;
[scrollView addSubview: footImageView];
UIImage *handImage = [UIImage imageNamed:@"Hand.png"];
UIImageView *handImageView = [[UIImageView alloc] initWithImage:handImage];
handImageView.frame = CGRectMake(90, 0, 80, 78);
handImageView.userInteractionEnabled = YES;
[scrollView addSubview: handImageView];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(highlightImage)];
[scrollView addGestureRecognizer:tapGesture];
NSLog(@"tapGesture added to scrollView");
[[cell contentView] addSubview:scrollView];
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 50, tv.frame.size.width, 50)];
[pageControl setNumberOfPages:4];
[[cell contentView] addSubview:pageControl];
我tapGesture
正在向选择器注册hightlightImage
,并且只是记录它正确调用此方法。
- (void) highlightImage
{
NSLog(@"tapping tapping");
}
我真正在努力的是能够在点击时突出显示/选择这些图像,如果再次点击则突出显示/取消选择它们。我将在屏幕上有另一个按钮导航到下一页(此处无关)。
我在这里走正确的道路吗?显然,我将填充一个NSArray
ofUIImages
并以scrollView
这种方式填充,但现在只是将其添加出来。如果有人可以给我一些指导或示例,说明如何使每个按钮分别可选择/取消选择,那就太好了:)