Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: [ Ссылка ]
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Is there any way to using UICollectionViewCell's self-sizing only in vertical direction?
I am writing a demo about the difference using compositional layout & traditional flow layout with UICollectionView.
UICollectionView
I found that if I want to set the cell’s width equal to the UICollectionView’s width , but the cell’s height is determined by the cell’s content (self-sizing only in vertical).
UICollectionView
This can be easily with compositional layout
let height = NSCollectionLayoutDimension.estimated(144)
let itemSize = NSCollectionLayoutSize(widthDimension: NSCollectionLayoutDimension.fractionalWidth(1), heightDimension: height)
But, if I use traditional flow layout, I can only set flow layout’s estimatedItemSize like this:
layout.estimatedItemSize = CGSizeMake(collectionView.width, 140)
But, after layout, the cell’s final width will always determined by the actual content, not the width equal to collectionView’s width.
This can be easily with compositional layout
let height = NSCollectionLayoutDimension.estimated(144)
let itemSize = NSCollectionLayoutSize(widthDimension: NSCollectionLayoutDimension.fractionalWidth(1), heightDimension: height)
This can be easily with compositional layout
let height = NSCollectionLayoutDimension.estimated(144)
let itemSize = NSCollectionLayoutSize(widthDimension: NSCollectionLayoutDimension.fractionalWidth(1), heightDimension: height)
let height = NSCollectionLayoutDimension.estimated(144)
let itemSize = NSCollectionLayoutSize(widthDimension: NSCollectionLayoutDimension.fractionalWidth(1), heightDimension: height)
But, if I use traditional flow layout, I can only set flow layout’s estimatedItemSize like this:
layout.estimatedItemSize = CGSizeMake(collectionView.width, 140)
But, after layout, the cell’s final width will always determined by the actual content, not the width equal to collectionView’s width.
But, if I use traditional flow layout, I can only set flow layout’s estimatedItemSize like this:
estimatedItemSize
layout.estimatedItemSize = CGSizeMake(collectionView.width, 140)
layout.estimatedItemSize = CGSizeMake(collectionView.width, 140)
But, after layout, the cell’s final width will always determined by the actual content, not the width equal to collectionView’s width.
collectionView
Is there any best practice about this kind vertical-only self-sizing?
Tags: ios,uicollectionview,uikit,uicollectionviewlayout,uicollectionviewflowlayoutSource of the question:
[ Ссылка ]
Question and source license information:
[ Ссылка ]
[ Ссылка ]
Ещё видео!