Created
June 29, 2020 07:24
-
-
Save ozgurshn/c816a035ff4722dc26650f4a4ed40105 to your computer and use it in GitHub Desktop.
Using SVGKit in Swift UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import SVGKit | |
struct SVGKFastImageViewSUI:UIViewRepresentable | |
{ | |
@Binding var url:URL | |
@Binding var size:CGSize | |
func makeUIView(context: Context) -> SVGKFastImageView { | |
// let url = url | |
// let data = try? Data(contentsOf: url) | |
let svgImage = SVGKImage(contentsOf: url) | |
return SVGKFastImageView(svgkImage: svgImage ?? SVGKImage()) | |
} | |
func updateUIView(_ uiView: SVGKFastImageView, context: Context) { | |
uiView.image = SVGKImage(contentsOf: url) | |
uiView.image.size = size | |
} | |
} | |
struct SVGImage_Previews: PreviewProvider { | |
static var previews: some View { | |
SVGKFastImageViewSUI(url: .constant(URL(string:"https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/android.svg")!), size: .constant(CGSize(100,100))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This downloads image from url every update