Skip to main content

Animating view colour changes

Updated:

When animating the addition of cells to a UICollectionView, we may notice that text and background colours aren't animating when using UIView.animate. Using UIView.transition instead works perfectly!

UIView.transition(with: commentContainer, duration: 0.6,
                  options: .transitionCrossDissolve, animations: {
   commentContainer.backgroundColor = UIColor(red: 17, green: 215, blue: 198)
})

UIView.transition(with: commentLabel, duration: 0.6,
                  options: .transitionCrossDissolve, animations: {
   commentLabel.textColor = UIColor(red: 143, green: 155, blue: 174)
})

I hope the article was useful. If you have any feedback or questions please feel free to reach out.

Thanks for reading!

Like what you read? Please share the article.

Avatar of Andrew Lord

WRITTEN BY

Andrew Lord

A software developer and tech leader from the UK. Writing articles that focus on all aspects of Android and iOS development using Kotlin and Swift.

Want to read more?

Here are some other articles you may enjoy.