Search code examples
iosfor-loopif-statementbuttonswift3

How to use a loop to increase a scroll view size (swift3)


Right now every time the button is pressed a the score goes up. Once the score hits 3 the scrollviews height is increased. How can I make this so every time the button is pressed the height increases by 50 for a infinite amount of times.

@IBAction func enterScore(_ sender: Any) {
        score += 1


            THESCROOL.contentSize.height = 1000
            if score >= 3 {
                THESCROOL.contentSize.height = 5000

            }}

Solution

  • Not sure i fully understand your question. Do you want to do something like this?

    @IBAction func enterScore(_ sender: Any) {
        score += 1
    
        // every time the button is pressed, the contentHeight is increased by 50
        THESCROOL.contentSize.height = THESCROOL.contentSize.height + 50
    }