我有一个带有自定义单元格的 UITableView。
我想在每个单元格中实现这种 UIScrollView。
每个滚动视图中我可以拥有的最大图像数量是 5。它可以更少,但不能更多。
我有图形和一切。我想用 UIPageControl 来实现它,因此当前图像将在 pageControl 中标记,因此我可以将其框架更改为绿光。
我现在正在使用此代码- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
:
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(12,202,295,91)];
self.scrollView.showsHorizontalScrollIndicator = NO;
NSMutableArray *imageArray = [[NSMutableArray alloc]init];
for (int i=0; i<[[[self.campArray objectAtIndex:[indexPath row]]valueForKey:@"images"]count]; i++) {
UIImageView * imageView =[[UIImageView alloc] initWithFrame:CGRectMake(i*130, 0, 108, 92)];
[imageView setImage:[UIImage imageNamed:@"Frame-03.png"]];
UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 96, 81)];
[imgV setImageWithURL:[NSURL URLWithString:[[[[self.campArray objectAtIndex:[indexPath row]]valueForKey:@"images"]objectAtIndex:i]valueForKey:@"thumbnailURL"]]];
imgV.contentMode=UIViewContentModeScaleToFill;
imgV.tag=i+1;
[imageView addSubview:imgV];
[imageArray addObject:imageView];
[imageView release];
[imgV release];
}
NSInteger numberOfViews = imageArray.count
;
for (int i = 0; i < numberOfViews; i++) {
[self.scrollView addSubview:[imageArray objectAtIndex:i]];
}
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomImage)];
[self.scrollView addGestureRecognizer:singleTap];
self.scrollView.tag = [indexPath row];
UIPageControl *pgCtr = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 108, 81)];
pgCtr.numberOfPages=numberOfViews;
pgCtr.autoresizingMask=UIViewAutoresizingNone;
[cell.contentView addSubview:pgCtr];
//set the scroll view content size
self.scrollView.contentSize = CGSizeMake(130 *
numberOfViews,
self.scrollView.frame.size.height);
//add the scrollview to this view
[cell.contentView addSubview:self.scrollView];
return cell;
谢谢!