我正在使用ALScrollViewPaging库进行图像分页,我将此代码集成到UITableviewCell中。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PoastCell *cell;
cell=[tblBoardDetail dequeueReusableCellWithIdentifier:@"PoastCell" forIndexPath:indexPath];
NSDictionary *dict=[arrPosts objectAtIndex:indexPath.row];
ALScrollViewPaging *scrollView = [[ALScrollViewPaging alloc] initWithFrame: CGRectMake (0, 0, self.view.frame.size.width, 200)];
scrollView.showsHorizontalScrollIndicator=NO;
NSMutableArray *views = [[NSMutableArray alloc] init];
for (NSString *strImages in [dict valueForKey:@"post_image"])
{
UIView *catView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,200)];
UIImageView *imageView = [[UIImageView alloc] init];
imageView.contentMode=UIViewContentModeScaleAspectFill;
[Common loadImgFromUrl:strImages :imageView];
imageView.frame = catView.bounds;
[catView addSubview:imageView];
[views addObject:catView];
}
[scrollView addPages:views];
[cell.imagePagingView addSubview:scrollView];
[scrollView setHasPageControl:YES];
}
答案 0 :(得分:0)
我建议您以编程方式使用Scrollview进行页面控制,这比使用库更容易。
创建一个pagecontrol属性:
@property (nonatomic, weak)UIPageControl *pageControl;
不要忘记将您的课程设置为UIScrollViewDelegate
@interface ViewController() <UIScrollViewDelegate>
然后在你的单元格中制作一个scrollview:
//scrollview
CGRect scrollViewFrame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 200);
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:scrollViewFrame];
[scrollView setPagingEnabled:YES];
[scrollView setShowsHorizontalScrollIndicator:NO];
// i is the number of images you want to display
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * i, scrollView.bounds.size.height);
scrollView.delegate = self;
//page control. i is equals to number of dots you want
self.pageControl = [[UIPageControl alloc] init];
CGRect pageControlFrame = CGRectMake(0.0, 0.0, 0.0, 0.0);
self.pageControl.frame = pageControlFrame;
//i is equals to number of dots you want
self.pageControl.numberOfPages = i;
NSDictionary *dict=[arrPosts objectAtIndex:indexPath.row];
for (NSString *strImages in [dict valueForKey:@"post_image"]) {
//imageview
CGRect imageViewFrame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 200);
UIImageView *imageContainer = [[UIImageView alloc] initWithFrame:imageViewFrame];
imageContainer.image = SET_YOUR_IMAGE_HERE;
imageContainer.contentMode = UIViewContentModeScaleAspectFill;
CGRect frame = scrollView.frame;
frame.origin.x = scrollViewFrame.size.width * i;
imageContainer.frame = frame;
[scrollView addSubview:imageContainer];
}
[cell addSubview:self.pageControl];
[cell addSubview:scrollView];
}
//this highlight the dot of the page you scroll to
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSInteger page = scrollView.contentOffset.x / scrollView.frame.size.width;
self.pageControl.currentPage = page;
}