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 ?
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.
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.
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.
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.
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.
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.
Use this UICollectionViewDelegateFlowLayout
method
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With