Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic size UICollectionView cell

enter image description here

1) How can i achieve as shown in image with UICollectionView?

2) I've tried -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath method & passed different sizes but it leaves out spaces between cells. Can i empty those spaces? I want different height & width for every cell

Current output: enter image description here.

like image 613
Akshit Zaveri Avatar asked May 20 '14 12:05

Akshit Zaveri


People also ask

How do I resize a collection view cell?

First you have to Add the UICollectionViewDelegateFlowLayout delegate and then use following delegate method it will work fine for me. Show activity on this post. Implement the below method,, it is autoresized base on the screen you have.

What is Uicollectionviewflowlayout?

A layout object that organizes items into a grid with optional header and footer views for each section.


1 Answers

Sorry this is super late... But maybe this will help people who haven't found an answer yet. If you have your images in an array, you can simply reference the image size and make the adjustments to the cell size from there:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {     UIImage *image = [imageArray objectAtIndex:indexPath.row]; //You may want to create a divider to scale the size by the way..     return CGSizeMake(image.size.width, image.size.height);  } 

Hope this helps..

like image 74
RobMillerJ25 Avatar answered Oct 12 '22 02:10

RobMillerJ25