gpt4 book ai didi

ios - 动态改变 UIView 高度

转载 作者:行者123 更新时间:2023-11-28 13:10:50 24 4
gpt4 key购买 nike

我试图根据其中的内容量允许 subview ( View 内的白框。 View Controller swift 文件是一个单独的 XIB 文件)的高度。我该怎么做呢?

Imgur

这就是我目前所拥有的:

@IBOutlet weak var myScrollView: UIScrollView!
@IBOutlet weak var myContentView: UIView!

override func viewDidLayoutSubviews()
{
let scrollViewBounds = myScrollView.bounds
let containerViewBounds = //I am not sure how to do the rest


}

最佳答案

实现此目的的最佳方法是使用自动布局。你在这里有很棒的教程:

http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

如果您不想使用它,请在您的 View Controller 中为您的 View 设置该 View 的引用,并使用各种函数来计算高度。标签(Adjust UILabel height to text)、文本字段(How to set UITextField height?)等有多种方式。

关于ios - 动态改变 UIView 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31363087/

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