Question:
How To Make UITableViewCell
Height Dynamic according the UICollectionViewCell
?
View Hierarchy:
UIViewController
UITableView
UITableViewCell
UICollectionView
UICollectionViewCell1
Label 1
UICollectionViewCell2
Label 2
UICollectionViewCell3
Label 3
[So on]
Explanation:
Here Label1
, Label2
, label 3
are have dynamic height and numberOfRows
in UICollectionView
is also dynamic. I need Height of UITableViewCell
according to the UICollectionViewCell
.
View Hierarchy In
UIViewController
Steps:
Bind Delegate And Datasource
Bind
UItableView
Delegate and datasource with theUIViewController
.Bind
UICollectionView
Delegate and datasource with theUItableViewCell
hereTblCell
.In
UIViewController
In
TblCell
Output:
Black Outline : Label
with UICollectionViewDelegateFlowLayout
without UICollectionViewDelegateFlowLayout
Reference:
UICollectionView inside a UITableViewCell -- dynamic height?
Note :
TableViewCell height is based on collectionview content size i.e. if same tableCell have any other UI component other than collectionview or there is top bottom margin for collectionView then it won't be calculated. For this, you can create multiple cells in which one cell only contain collectionview (Best Approach for now) or you can return your actual tableview cell height in
systemLayoutSizeFitting
by calculation.how to give height to cell accorting to text in swift