Tuesday, June 30, 2026
HomeiOS DevelopmentPresent button picture with delay - Swift IOS

Present button picture with delay – Swift IOS

[ad_1]

I needed to point out a picture within the button when the person presses it. I attempted utilizing the sleep() methodology but it surely solely made the button dim and didn’t present the picture whereas it was at this dim state.

@objc func cardPressed(_ sender: UIButton){
    
    sender.setImage(buttonCardDict[sender]?.cardImage, for: .regular)
    selectionCount += 1
    
    if selectionCount == 1 {
        
        firstCard = sender
        
    } else if selectionCount == 2 {
        
        secondCard = sender
        
        var areEqual: Bool = false
        if buttonCardDict[firstCard!]?.cardImage == buttonCardDict[secondCard!]?.cardImage {
            areEqual = true
        }
        
        if areEqual == false {
            
            sleep(3)
            
            firstCard?.setImage(#imageLiteral(resourceName: "card_back"), for: .regular)
            secondCard?.setImage(#imageLiteral(resourceName: "card_back"), for: .regular)
        }
        
        selectionCount = 0
        
    }
    
}

What’s the correct means on this case to point out the picture, wait a number of seconds, after which proceed the code?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments