tableview中cell用stackview控件 cell中label在storyboard中设置line为0
tableview中设置两行代码:
tableView.rowHeight =UITableViewAutomaticDimension
tableView.estimatedRowHeight =240
stackview设置问题
cell中的iconImageview的图片 storyboard中设置clip to Bounds 防止图片蹿出去。
content mode 设置为aspect fill
如果content Mode设置为scale fill图片会被拉伸
Aspect Fill:在保持长宽比的前提下,缩放图片,使图片充满容器。
Aspect Fit:在保持长宽比的前提下,缩放图片,使得图片在容器内完整显示出来。
Scale to Fill: 缩放图片,使图片充满容器。图片未必保持长宽比例协调,有可能会拉伸至变形。
stackview中有三个label更改其间距设置Spacing
本文探讨了在TableViewCell中使用StackView进行布局时遇到的问题,包括如何设置StackView以适应不同内容的Label,以及如何处理cell的高度自适应。通过设置tableView.rowHeight和estimatedRowHeight实现cell高度自动计算。对于StackView中的iconImageView,建议在storyboard中启用clip to Bounds并设置content mode为Aspect Fill,以防止图片溢出且保持比例。同时,对比了Aspect Fill、Aspect Fit和Scale to Fill三种content mode的差异。此外,还介绍了如何调整StackView中Label的间距(Spacing)。
4758

被折叠的 条评论
为什么被折叠?



