根据动态 UIView 的给定宽度计算高度

问题描述 投票:0回答:0

我有一个 UIView,它由许多动态子视图组成,包括 UIStackView。

我必须添加这个 UIView 作为我的 tableFooter,所以我需要计算它的高度。我尝试使用以下两种方法计算高度,但尺寸不正确且为零。

//got incorrect size
let targetSize = CGSize(width: 300, height: UIView.layoutFittingCompressedSize.height)
let prefSizs = footerView.systemLayoutSizeFitting(targetSize)
footer.frame = CGRect(x: 0, y: 0, width 300, height: prefSize.height)

//got zero frame
let frame = footerView.frame

我是否可以根据给定的宽度为我的动态 UIView 找到正确的高度?

swift uitableview uiview uiviewcontroller uikit
© www.soinside.com 2019 - 2024. All rights reserved.