gpt4 book ai didi

swift - 设置 UITableView 标题 View 高度取决于其 subview

转载 作者:行者123 更新时间:2023-11-30 12:58:48 27 4
gpt4 key购买 nike

我的 UITableView 中有一个 headerview,但我找不到使其动态高度的解决方案。在我的 headerview 中,我有一个 UITextView ,其高度取决于其内容。

到目前为止我已经尝试过了。

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
sizeHeaderToFit()
}


func sizeHeaderToFit() {

let headerView = mTabView.tableHeaderView!

mTxtViewDescription.sizeToFit()
mConDescriptionHeight.constant = mTxtViewDescription.frame.height

print(mContainerView.frame.maxY)

headerView.frame.size.height += mTxtViewDescription.frame.height


}

绿色区域是我的标题 View

enter image description here

最佳答案

更改已设置的 UITableView header 的框架高度不会重新计算高度,这意味着您不能仅更改 tableHeaderView 的高度,因为其布局由 tableView 管理。您需要再次设置tableHeaderView,设置该属性会触发新的计算。有很多关于此问题的详细问题,其中几个链接自 this one

关于swift - 设置 UITableView 标题 View 高度取决于其 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40095997/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com