如何加载滚动视图中的图像捆绑与iPhone中的horrizondal滚动?

我有一个iPhone应用程序,其中我需要加载大量的图像(即50左右),其中有一个小的矩形像(略高于缩略图),每行包含3行,在一页中的4列,我需要水平滚动加载下12张图片等等。 另外我需要显示它下面的页码为1,2等。 像附加的图像

任何人都可以在正确的方向指导我在滚动视图中实现这一目标吗?我真的是一团糟,如何将imageview添加到像这样的滚动视图,每个图像视图也有自己的button。

我将解决这个问题的方式如下:(我不会提供许多细节,因为它们取决于您的特定需求和要求)。

.h文件:

#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIScrollViewDelegate> @property (unsafe_unretained, nonatomic) IBOutlet UIScrollView *scrollView;//assuming the scrollView is connected in a xib file -(id)initWithImages:(NSArray*)images;//that could be whatever format you get your images(UIImage, urls to download, file names or custom views. Here we assume that the array contains instances of UIImage) @end 

.m文件:

 #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) NSArray *images; @property (nonatomic, assign) CGFloat pageWidth; @property (nonatomic, assign) int currentPage; @end @implementation ViewController -(id)initWithImages:(NSArray*)images{ self = [super init]; if(self){ self.images = images; } return self; } -(void)viewDidLoad{ [super viewDidLoad]; [self.scrollView setDelegate:self]; [self.scrollView setContentSize:CGSizeMake(self.scrollView.frame.size.width*self.imageURLsArray.count, self.scrollView.frame.size.height)]; [self.scrollView setPagingEnabled:YES]; [self.scrollView setShowsVerticalScrollIndicator:NO]; self.pageWidth = self.scrollView.frame.size.width; for(int i = 0; i < self.images.count; i++){ UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.scrollView.frame.size.width*i, self.scrollView.frame.origin.y, self.scrollView.frame.size.width, self.scrollView.frame.size.height)]; imageView.image = [self.images objectAtIndex:i]; [self.scrollView addSubview:imageView]; } } -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ int page = floor(scrollView.contentOffset.x - self.pageWidth/2)/self.pageWidth + 1; if(self.currentPage != page){ NSLog(@"Scrolled to new page: %d", page); self.currentPage = page; //do additional things based on the fact that you have scrolled to a new page (like changing the page number) } } @end 

使用UItableview创build自定义单元格,并在其上创build两个图像视图,然后将该自定义单元格加载到单元格中作为索引path,然后创build一个nsarray并将图像名称传入该数组,然后将该图像转换为数据格式

nsdata * data = [NSdata dataWithcontents of url [array object at index:indexpath.row]]; cell.imageview.image = [uiimage imagewithdata:data]; 为此,您应该知道创build自定义单元格。