0

i want to make an image with transparent background which is capture by me and there should be only edges of image.

Then after i want to change color of that image's edges.

so suggest me is there any way to do this.

thanks

UPDATE

My question is not duplicate because the difference is:

  1. i want load svg url only into imageView not into webView
  2. there should be change tint color of svg image which loaded into image view.
  • 1
    Possible duplicate of [How to display .svg image using swift](https://stackoverflow.com/questions/35691839/how-to-display-svg-image-using-swift) – slobodans Nov 02 '18 at 13:22

2 Answers2

1

Use this to upload the image from the url

func download(url:String) {

    let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];

    let filePath="\(documentsPath)/img.svg"

    DispatchQueue.global(qos: .background).async {

        if let url = URL(string: "\(url)/img.svg"),

            let urlData = NSData(contentsOf: url) {

            DispatchQueue.main.async {

                urlData.write(toFile: filePath, atomically: true)

                print("done")

            }
        }
    }
}

How to use

download(url: "https://yuordomin.com/nameimge.svg")
gms
  • 144
  • 1
  • 8
0

EDIT My answer ignores the aspect that you explicitly want SVG images, sorry for that; still, you could convert your images to PDF and use the described approach.


You can use use the renderingMode property of UIImage to generate a template image which supports setting a tint color. This will interpret all non-transparent pixels as the "foreground" which will get colored by the tint.

There are two ways to do so:

  1. Set the image's render mode in the asset catalog by opening the Attributes Inspector and setting the dropdown Render as to Template Image. When you load this image with UIImage(named:) you automatically get it as a template image.
  2. When you already have the UIImage instance you can convert it to a template image: let templateImage = image.withRenderingMode(.alwaysTemplate)

In both cases you can set the tint color of the image with templateImage.tintColor = yourColor.

dr_barto
  • 5,723
  • 3
  • 26
  • 47
  • here i am getting .svg url into api response and that .svg url show directly into my image view . is it possible to show in image view directly? thanks – Manish Patel Nov 03 '18 at 06:40