Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.76 KB

File metadata and controls

59 lines (45 loc) · 1.76 KB

Platform Language

Dynamic Height For UICollectionView

  • Simple solution for Dynamically adjust view as a blocks.
  • Dynamically adjust height of collection view.
  • No more White spaces

Difference between Normal CollectionView Layout and Custom CollectionView Layout

While using Dynamic height only While using Dynamic height with Custom Layout Made by Me
ScreenShot ScreenShot

How to get Custom CollectionView Layout for your UICollectionView

Add Following Files to your project

  • customLayout.h
  • customLayout.m

Import customLayout in your controller where to use

#import "customLayout.h"

And use

<customLayoutDelegate> 

to your controller.

Write Simple Code in your viewDidLoad Method

    columncount=2; // How much Columns you required
    miniInteriorSpacing=10; // Minimum Spacing you required
    
    if(![collectionView.collectionViewLayout isKindOfClass:[customLayout class]]){
        customLayout *layout = [customLayout new];
        layout.delegate=self;
        layout.columnCount=columncount;
        
        collectionView.collectionViewLayout = layout;
        
        [collectionView reloadData];
    } 

For getting height of Label I have written a method.

-(float)calculateHeightForLbl:(NSString*)text width:(float)width;