简体   繁体   中英

UIStackView inside UIScrollView with dynamically changing items

I'm trying to have a UIStackView in a UIScrollView with changing content in the UIStackView as shown below in the image. How ever I don't manage to get it to work properly. When I launch my app it does not scroll and only 10 items are shown in the stack view, not the 20 I expected. Also it does not scroll all the way down of the UIStackView .

Note it's important that this can work on both iPhone and iPad even when rotated.

场景

I have the following code in my View Controller (that's all):

@IBOutlet weak var stackView: UIStackView!

override func viewDidLoad() {
    super.viewDidLoad()

    for i in 1 ... 20 {
        let vw = UILabel()
        vw.text = "Holiday #\(i)"
        stackView.addArrangedSubview(vw);
    }
}

I found a solution using this as a foundation: https://github.com/oliverfoggin/AnimalBrowser

The code remains the same, but I changed around a bit on the scene and now it works!

场景

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM