In my CollectionView which is horizontal, not displaying the views properly. Why?
In the pictures shown below pink color is CollectionView and orange color is cell why cells are displayed oddly. For cell 1 there is right side space and for cell 2 there is leftside space and for cell 3 the size is increased on left a bit. why this odd behavior?
Here is my code :
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 3;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionViewCell* cell = (CollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"pagerCell" forIndexPath:indexPath];
[cell.PagerViewCell addSubview: [[[NSBundle mainBundle] loadNibNamed:@"AlbumsView" owner:self options:nil] objectAtIndex:0]];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(pagerView.frame.size.width , pagerView.frame.size.height);
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 1;
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
[pagerView.collectionViewLayout invalidateLayout];
}