2

This is the menu for my app and I generate different color themes such as:

enter image description here

I'm using the following method to recolor each menu items icon:

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

After calling the function, I get the result below where I'm losing the gradient:

enter image description here

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.

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 (link to another thread) or export a specific colored png for each icon which would be counter productive in my opinion?

Any help would be well appreciated :D

Thanks!

Community
  • 1
  • 1
Carmelo
  • 49
  • 1
  • 7
  • You are going to lose the gradient when you render the image as a template. That essentially is stripping the color from the image and redefining areas of the image as being filled in or void. When you then tint the image view, all areas that need to be filled in will be filled with that color. If you need a gradient, you're going to have to do it manually. Take a look here for ideas: http://stackoverflow.com/questions/8098130/how-can-i-tint-a-uiimage-with-gradient – Dare Aug 24 '16 at 17:30
  • @Dare Thanks for your feedback. Yes, I'm aware of that StackOverflow thread (it is at the bottom of my question). It seems I have to do it that way then... :D – Carmelo Aug 25 '16 at 11:38

0 Answers0