I am having similar problem like this
I am generating height of view at run time.Here is my code
@interface CollectionViewController ()
{
NSMutableAr
The class that you inherited from UICollectionViewFlowLayout
must contain methods :
- (CGSize)collectionViewContentSize
{
return CGSizeMake(200, 200) // as per your cell size
}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray* attributesToReturn = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes* attributes in attributesToReturn)
{
if (nil == attributes.representedElementKind)
{
NSIndexPath* indexPath = attributes.indexPath;
attributes.frame = [self layoutAttributesForItemAtIndexPath:indexPath].frame;
}
}
return attributesToReturn;
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes* currentItemAttributes =
[super layoutAttributesForItemAtIndexPath:indexPath];
if (!currentItemAttributes)
{
currentItemAttributes = [UICollectionViewLayoutAttributes
layoutAttributesForCellWithIndexPath:indexPath];
}
return currentItemAttributes;
}
And in Your CollectionViewController add
#pragma mark - Collection View Datasource
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Adjust cell size for orientation
if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
{
return CGSizeMake(150, 230);
}
return CGSizeMake(150, 230);
}