Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different cell size in UICollectionview

Tags:

In my iphone app,I am showing images on a collection view. I fetch the images from urls,with urls I get the image size also. eg:- let's say there are two kinds of images landscape and portrait.I get value P for portrait images and L for landscape images

How to customize the collectionView cell's size ?

like image 935
New Jango Tester Avatar asked Apr 17 '13 13:04

New Jango Tester


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.

Do CollectionView use cells?

CollectionView has no concept of cells. Instead, a data template is used to define the appearance of each item of data in the list. CollectionView automatically utilizes the virtualization provided by the underlying native controls.

What is self-sizing cell in uicollectionviewflowlayout?

Self-sizing is a way of adjusting cells size within collection view layout, where cells are responsible for calculating their own sizes. Three ways to cut the cake exist: Layout Property — UICollectionViewFlowLayout.itemSize. Delegate — collectionView (layout:sizeForItemAt:). Cell — self-sizing cells.

What is a custom cell in uicollectionview list?

A custom cell of a UICollectionView list is a subclass of UICollectionViewListCell. It has only 1 task — generate a properly configured content configuration object based on the state (selected, highlighted, disabled, etc.) of the cell and then assign the configuration to itself.

Why do cells have different sizes in uicollectionview?

Sometimes we need to be UICollectionView’s Cells have size depend on their content and the most common example is the feeds in social websites every post has a different size as well as their comments.

Why does my uicollectionview say “the item width must be less”?

You’ll notice numerous debugger warnings, saying that “The item width must be less than the width of the UICollectionView …“. This reveals the need to constraint cells horizontally and force them to grow in height. Enabling vertical self-sizing is a two-step process. Firstly, titleLabel need to be multi-line to support vertical growing.


1 Answers

Use this UICollectionViewDelegateFlowLayout method

 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath; 
like image 200
Anil Varghese Avatar answered Oct 08 '22 19:10

Anil Varghese