ios – Why utilizing withRenderingMode is required when assigning UIImage to UIImageView/ UIButton?

[ad_1]

After I got here throughout many of the examples, I discover nearly all of them are utilizing withRenderingMode, when assigning an UIImage to UIImageView, UIButton, …

Examples are :-

Motion Sheet with Picture for every choice on iOS

Is there any manner to make use of “withRenderingMode(.alwaysTemplate)” with default picture by not including any tint color of a button?

My preliminary ideas is that, the aim of utilizing withRenderingMode, is to generate a brand new occasion of UIImage, in order that altering the tint shade of an UI element, won’t have an effect on remainder of others.

I wrote a easy program with out utilizing withRenderingMode

class ViewController: UIViewController {
    
    @IBOutlet weak var imageView1: UIImageView!
    
    @IBOutlet weak var imageView2: UIImageView!

    @IBOutlet weak var imageView3: UIImageView!
    
    override func viewDidLoad() {
        tremendous.viewDidLoad()

        let chooseImage = UIImage(systemName: "photograph")
        
        imageView1.picture = chooseImage
        
        imageView2.picture = chooseImage
        
        imageView3.picture = chooseImage
        
        imageView1.tintColor = .crimson
        
        imageView2.tintColor = .inexperienced
    }

I count on all UIImageView will find yourself of getting identical picture shade, but it surely does not occur.

enter image description here

Can anybody present an instance, on when utilizing withRenderingMode is admittedly essential?

Thanks.

[ad_2]

Leave a Reply