How to display .svg image using swift
Try this code
var path: String = NSBundle.mainBundle().pathForResource("nameOfFile", ofType: "svg")!
var url: NSURL = NSURL.fileURLWithPath(path) //Creating a URL which points towards our path
//Creating a page request which will load our URL (Which points to our path)
var request: NSURLRequest = NSURLRequest(URL: url)
webView.loadRequest(request) //Telling our webView to load our above request
unable to get image from URL to update in UIImage in swift
I tried installing SVGKit as given in the below reference link and it works for me.
How to display .svg image using swift
DispatchQueue.global(qos: .background).async { [weak self] () -> Void in
if let url = NSURL(string: "https://restcountries.eu/data/est.svg"){
if let data = NSData(contentsOf: url as URL) {
let imageAux = UIImage(data: data as Data)
DispatchQueue.main.async {
let anSVGImage: SVGKImage = SVGKImage(data: data as Data)
cell.imgFlag.image = nSVGImage.uiImage
}
}
}
}
in ur existing code just add one line of code:
let anSVGImage: SVGKImage = SVGKImage(data: data as Data) and it worked at my end.
Why can't I convert the `svg` data to UIImage using `SVGKit` in Swift 4?
If you are image is using gradient effect then it will not work in SVGKit. Check whether your image is using any gradient effect.
Apple's rendering DOES NOT ALLOW US to render this image correctly
using SVGKFastImageView, because Apple's renderInContext method -
according to Apple's docs - ignores Apple's own masking layers. Until
Apple fixes this bug, you should use SVGKLayeredImageView for this
particular SVG file (or avoid using gradients)
Related Topics
How to Open Amazon App from Within My App
Ios: How to Create Expandable Tableview in Swift Without Using Third Party Libraries or Pods
Passing Data Between View Controllers in Swift (From Tableview to Detailviewcontroller)
Admob Interstitial Alway Returns False
Xcode 9.3 - Nspredicate Bool Crash
How to Access Property or Method from a Variable
Automatically Increase/Decrease Uilabelview Height in Uitableviewcell
How to Set Response Data into Todayextenstion Widget
Convert Uiview to .Png in Swift
Delegate Seems to Not Be Working, According to the Console
Can't Change Uinavigationbar Prompt Color
Error "Call Can Throw, But Is Not Marked with 'Try' and the Error Is Not Handled"
Required Initializers for a Subclass of Uiviewcontroller
Swift3 - How to Protect Secret Key
Random Number from an Array Without Repeating the Same Number Twice in a Row