Tint UIimage with gradient colors to another color
<p>This is the menu for my app and I generate different color themes such as:</p>

<p><a href="https://i.stack.imgur.com/S6bDj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S6bDj.jpg" alt="enter image description here"></a></p>

<p>I'm using the following method to recolor each menu items icon:</p>

<pre><code>  func recolorImage(imgView: UIImageView, toColor: UIColor) {
    let imgTintColor = imgView.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
    imgView.image = imgTintColor
    imgView.tintColor = toColor
  }
</code></pre>

<p>After calling the function, I get the result below where I'm losing the gradient:</p>

<p><a href="https://i.stack.imgur.com/66Gfn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/66Gfn.jpg" alt="enter image description here"></a></p>

<p>Sorry in advance for my ignorance (still a newbie), it seems to be that the method will remove all colors, including gradients and then apply the tintcolor.</p>

<p>I wonder if there is another function to do the job?
Or should I create custom class with a gradient mask applied to each icon (<a href="https://stackoverflow.com/questions/8098130/how-can-i-tint-a-uiimage-with-gradient">link to another thread</a>) or export a specific colored png for each icon which would be counter productive in my opinion?</p>

<p>Any help would be well appreciated :D</p>

<p>Thanks!</p>