how to show multiple value in one label using fade in fade out

Viewed 45

I want to show multiple quotation in one label. when one quotes fade out then another quotes fade in. I am doing this -:

  for i in self.splashModel?.quotations ?? [] {
        self.quoteLabel.alpha = 0
        print("CheckQuotes\(i)")
        Timer.scheduledTimer(withTimeInterval: 0.2, repeats: true, block: { timer in
            self.quoteLabel.text = i
            self.quoteLabel.fadeIn(completion: {
                    (finished: Bool) -> Void in
                    self.quoteLabel.fadeOut()
                    })
        })
       
    }

this only show last item of array

1 Answers

Try this -:

self.splashModel?.quotations.enumerated().forEach { (index,item) in
DispatchQueue.main.asyncAfter(deadline: .now() + Double( index * 2) ) {
    self.quoteLabel.alpha = 0
    self.quoteLabel.text = item
    self.quoteLabel.fadeIn(completion: {(finished: Bool) -> Void in
       self.quoteLabel.fadeOut()
   })
} 

}

Related