1
我有UIScrollView和UICollectionView。在CollectionView中,它是25張100x100大小的圖像。當我運行我的應用程序時,顯示模擬器中的前12個圖像,然後向上滾動,然後顯示下一個圖像。那不是我的問題。我想以水平模式而不是垂直模式顯示圖像。意味着在第一頁顯示的12張圖像然後滾動水平,並顯示下一個圖像不垂直。請告訴我如何去做。UIScrollView與UICollectionView
謝謝。
#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