gpt4 book ai didi

ios - 如何使用 Swift 通过代码库增加和减少 UIView 高度

转载 作者:搜寻专家 更新时间:2023-11-01 06:49:53 25 4
gpt4 key购买 nike

在我的例子中,我必须在 Tableview 顶部添加 UIView,但由于滚动,它应该在 Tableview 内部。在这里,我将 UIView 拖放到 topside tableview 上。现在,在某些情况下我需要增加 和减少 UIView 的高度。我尝试添加 constraints 但它不可用。如何通过代码库实现这一点?

带有 UIView Storyboard层次结构的 Tableview

enter image description here

Storyboard设计

enter image description here

禁用 UIView 的约束

enter image description here

最佳答案

Constraints 不适用于表格标题 View 。您可以使用自定义 View 设置表头并更新其框架

设置自定义 View

enter image description here

设置表头并更新它的框架

class ViewController: UIViewController {

@IBOutlet var tableView: UITableView!

@IBOutlet var tableHeader: UIView!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
loadHeader()
}

func loadHeader() {
tableHeader.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 300)
tableView.tableHeaderView = tableHeader
}
}

关于ios - 如何使用 Swift 通过代码库增加和减少 UIView 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58245681/

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