ios - Swift: ScrollView 自动布局

标签 ios swift uiscrollview

我需要在 ScrollView 中显示一些信息,它应该如下所示:

enter image description here

第一个 View 具有定义的高度,但第二个 View 具有动态高度。我知道如何使其动态,但我不知道如何使其在 ScrollView 中。它试图这样做,但没有成功。知道如何在 ScrollView 中制作这个场景吗?

没有 ScrollView :

enter image description here

里面。 ScrollView :

enter image description here

最佳答案

如果您的 View 仅垂直滚动,则应使用 UITableView 而不是 UIScollView

表格中的每个不同 View 都是一个UITableViewCell。对于每个单元格设置内容的自动布局约束,确保您的约束附加到单元格内容 View 的顶部和底部。为了使它更容易,请考虑在单元格内使用 UIStackView

然后在你的 TableView Controller 中......

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = <estimate of height>

...你的单元格将自行调整大小。

有大量资源可用于自动调整表格 View 单元格的大小......

关于ios - Swift: ScrollView 自动布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42648204/

相关文章:

c# - 测试中无法连接网络

ios - Cocos2d+Storyboards,我怎样才能得到一个工作项目?

ios - 为客户端临时分配管理 iOS UDID 的最佳方法是什么?

cocoa - fatal error : unexpectedly found nil while unwrapping an Optional value in Swift when tried to parse JSON

iOS 核心数据合并策略 - NSMergeByPropertyStoreTrumpMergePolicy

iphone - 滚动时调整 UICollectionView 的大小

ios - 可缩放的 UIImageView

ios - 如何在 uicollectionview header 中添加 uicollectionview

php - "JSON text did not start with array or object and option to allow fragments not set."

iphone - 具有不同页面宽度的 UIScrollview