我有UIScrollView和UICollectionView。在CollectionView中,有25个100x100大小的图像。当我运行我的应用程序时,它在模拟器中显示前12个图像然后我向上滚动然后显示下一个图像。那不是我的问题。我想以水平模式显示图像而不是垂直模式。表示在第一页显示12个图像然后水平滚动,并显示下一个不垂直的图像。请告诉我如何操作。
感谢。
#import "Collection.h"
#import "PageViewController.h"
@interface Collection ()
@end
@implementation Collection
@synthesize collView,selectedAlbum,img1;
static NSString *const cellReuseIdentifier = @"CollectionViewCell";
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.collView registerNib:[UINib nibWithNibName:@"CollectionViewItem" bundle:nil] forCellWithReuseIdentifier:cellReuseIdentifier];
self.collView.backgroundColor = [UIColor blackColor];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(100, 100)];
[flowLayout setMinimumLineSpacing:10];
[flowLayout setMinimumInteritemSpacing:10];
// [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[collView setCollectionViewLayout:flowLayout];
collView.delegate = self;
//Customize scrollView
scrolView = [[UIScrollView alloc] init];
scrolView.frame = CGRectMake(0, 0, 320, 400);
scrolView.delegate = self;
[self.view addSubview:scrolView];
scrolView.contentSize = CGSizeMake(0,0,640,450);
[scrolView addSubView:collView];
Images = [NSArray arrayWithObjects:@"3(3).jpg",@"baby1.jpg",@"Baby2.jpg",@"Baby3.jpg",@"boat_sea_beach-normal.jpg",@"cool.jpg",@"gold-iphone-5-300912.jpg",@"life-sometimes.jpg",@"Mac Wallpapers.jpeg",@"Quotes.jpg",@"series.jpg",@"wallpaper.jpg",@"wide-9.jpg", nil];
}
self.navigationItem.title = selectedAlbum;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return Images.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell1 = [collView dequeueReusableCellWithReuseIdentifier:cellReuseIdentifier forIndexPath:indexPath];
UIImageView *imageImages = (UIImageView *) [cell1 viewWithTag:16];
imageImages.image = [UIImage imageNamed:[Images objectAtIndex:indexPath.row]];
return cell1;
}
@end
答案 0 :(得分:0)
你需要用这个替换你的(注释的)scrolldirection:
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];