Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of svg images in ios?

I want to change color of svg images. I am using following code, it hides the image and fill the whole image view with the color set.

 self.badmintonImgView.tintColor = [UIColor orangeColor];

I need to change the color of image. Please suggest

like image 326
user Avatar asked Jul 15 '16 11:07

user


Video Answer


2 Answers

If the SVG is in Assets.xcassets, you can tell Xcode to treat the image as an icon:

First, select your SVG image in the assets catalog

Then set the render mode to Template Image

like image 169
אורי orihpt Avatar answered Nov 04 '22 02:11

אורי orihpt


Swift

To change the color of an SVG using Swift:

badmintonImgView.image = badmintonImgView.image?.withRenderingMode(.alwaysTemplate)
badmintonImgView.tintColor = UIColor.orange

enter image description here

like image 33
Marcy Avatar answered Nov 04 '22 04:11

Marcy