UIImage comes with property " renderingMode " from iOS 7 onwards. It can be set either 'alwaysTemplate' or 'alwaysOriginal'. This enum property helps us to re-use images that may thin your app size too. Let's get into to a real scenario ! I have added button as heart icon that gives like or dislike functionality for a picture. As you can see in the result below, heart image turns red when liked and stays gray when disliked. In such cases only one image asset can be used. Considering a UIButton object already created and added as a subview in the project, let's start with functionality. Again, I have only one image with name 'heart' in the asset folder (with gray fill). Using same image, I can create 2 instances of UIImage objects using rendering modes. let notLikedImage = UIImage . init (named: "heart" )?. withRenderingMode (. alwaysOriginal ) let likedImage = UIImage . init (named: "heart" )?....
Recently I published a countdown app . At one point of development - I have to show a timer on a UILabel which ticks on each seconds. As usual I started setting text to a label object - self .timerLabel.text = someString Easy piece of cake right !? But wait ... it won't take much user attention when timer ticks on every seconds. So I decided to make use of a simple animation while label gets text update. I found there are dozens of ways to animate a label. In this short article, I listed 3 best way you can animate text on a label. ( Spoiler Alert 👀- I decided to go with 3rd option) 1. Fade In - Fade out animation : CATransition class has got transition type `fade`. With timing function of CATransition - I was able to see the below result. let animation: CATransition = CATransition () animation.timingFunction = CAMediaTimingFunction (name: CAMediaTimingFunctionName .easeInEaseOut) animation.type = CATransitionType .fade animation.subtype = C...