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" )?....
Mobile App Developer | Technopreneur