简体   繁体   English

如何在swift中根据集合视图单元格内的标签内容自动调整高度?

[英]How to automatically adjust height based on label content inside collection view cell in swift?

收藏视图单元格 像这样

I want to achieve a self resizing height collection view cell (image above) using swift.我想使用 swift 实现自调整高度集合视图单元格(上图)。 I have tried many options like UICollectionViewDelegateFlowLayout and sizeforItem .我尝试了许多选项,例如UICollectionViewDelegateFlowLayoutsizeforItem Nothing works for me.没有什么对我有用。 I want to achieve similar result like in the image我想获得类似图像中的结果

在此处输入图像描述

Set Estimate size to automatic and do not implement sizeForItemAt , In CollectionView Cell, for each label give number of lines to zero.将 Estimate size 设置为自动并且不实现 sizeForItemAt ,在 CollectionView Cell 中,对于每个标签,将行数设为零。 It will resize automatically.它会自动调整大小。 Set Min spacing and line Spacing to zero as well将最小间距和行间距也设置为零

在此处输入图像描述

Also, In the collection View cell, three labels should be in stackView with fill allignment and distribution , set multiplier to center label width as 0.6 ( or whatever you want ) of total cell width.此外,在集合视图单元格中,三个标签应该在 stackView 中,填充对齐和分布,将乘数设置为中心标签宽度为总单元格宽度的 0.6(或任何你想要的)。 Give equal width constraint to first and last label like this image :为第一个和最后一个标签提供相等的宽度约束,如下图: 在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Swift iOS中调整集合视图单元格的高度? - How to adjust collection view cell height in swift ios? 如何基于其中的Web视图的html内容调整tableView单元格的高度? - How to adjust the height of a tableView Cell based on html content of the web-view inside it? 根据内容自动更改单元格高度 - Swift - Automatically change cell height based on content - Swift 根据内容动态调整tableview单元格的高度 - iOS Swift - Dynamically adjust the height of the tableview cell based on content - iOS Swift Swift - CompositionalLayout - 集合视图单元格高度未根据图像高度计算 - Swift - CompositionalLayout - collection view cell height not calculated based on Image height iOS-根据内容调整单元格高度 - IOS - Adjust cell height based on content 迅速:根据内部约束条件调整UIView高度 - swift: Adjust UIView height based on constraints inside UIButton根据标题调整视图高度(快速) - UIButton Adjust View Height Based on Title (Swift) 如何根据Swift3中的内容自动更改UICollectionView Cell的高度? - How to change the height of UICollectionView Cell automatically according to content in Swift3? 表格视图单元格内的表格视图自动调整单元格高度 - tableview inside tableview cell adjust cell height automatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM