Awesome
<a href="https://exyte.com/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/exyte/media/master/common/header-dark.png"><img src="https://raw.githubusercontent.com/exyte/media/master/common/header-light.png"></picture></a>
<a href="https://exyte.com/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/exyte/media/master/common/our-site-dark.png" width="80" height="16"><img src="https://raw.githubusercontent.com/exyte/media/master/common/our-site-light.png" width="80" height="16"></picture></a> <a href="https://twitter.com/exyteHQ"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/exyte/media/master/common/twitter-dark.png" width="74" height="16"><img src="https://raw.githubusercontent.com/exyte/media/master/common/twitter-light.png" width="74" height="16"> </picture></a> <a href="https://exyte.com/contacts"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/exyte/media/master/common/get-in-touch-dark.png" width="128" height="24" align="right"><img src="https://raw.githubusercontent.com/exyte/media/master/common/get-in-touch-light.png" width="128" height="24" align="right"></picture></a>
<p><h1 align="left">SVGView</h1></p> <p><h4>SVG parser written in SwiftUI</h4></p>Overview
The goal of this project is to bring the full power of SVG to Apple platforms. Our framework can parse SVG files and represent their content in SwiftUI. It provides you with the ability to not only render SVG files, but also add interactivity to them, handle user input and use SwiftUI to put your art into motion.
Usage
Get started with SVGView
in a few lines of code:
struct ContentView: View {
var body: some View {
SVGView(contentsOf: Bundle.main.url(forResource: "example", withExtension: "svg")!)
}
}
Customization
You can change various parameters for the nodes like this:
let circle = SVGCircle(cx: 30, cy: 30, r: 30)
circle.fill = SVGColor.black
circle.stroke = SVGStroke(fill: SVGColor(hex: "ABCDEF"), width: 2)
circle.onTapGesture {
print("tap")
}
Interact with vector elements
You may locate the desired part of your SVG file using standard identifiers to add gestures and change its properties in runtime:
struct ContentView: View {
var body: some View {
let view = SVGView(contentsOf: Bundle.main.url(forResource: "example", withExtension: "svg")!)
if let part = view.getNode(byId: "part") {
part.onTapGesture {
part.opacity = 0.2
}
}
return view
}
}
Animation
You can use standard SwiftUI tools to animate your image:
if let part = view.getNode(byId: "part") {
part.onTapGesture {
withAnimation {
part.opacity = 0.2
}
}
}
Complex effects
SVGView makes it easy to add custom effects to your app. For example, make this <a href="https://www.iconfinder.com/icons/1337497/">pikachu</a> track finger movement:
var body: some View {
let view = SVGView(contentsOf: Bundle.main.url(forResource: "pikachu", withExtension: "svg")!)
let delta = CGAffineTransform(translationX: getEyeX(), y: 0)
view.getNode(byId: "eye1")?.transform = delta
view.getNode(byId: "eye2")?.transform = delta
return view.gesture(DragGesture().onChanged { g in
self.x = g.location.x
})
}
<img src="https://i.imgur.com/Ij0Xn4A.gif" width="300" height="300">
SVG Tests Coverage
Our mission is to provide 100% support of all SVG standards: 1.1 (Second Edition), Tiny 1.2 and 2.0. However, this project is at its very beginning, so you can follow our progress on <a href="w3c-coverage.md">this page</a>. You can also check out <a href="https://github.com/exyte/SVGViewTests">SVGViewTests project</a> to see how well this framework handles every single SVG test case.
Installation
Swift Package Manager
dependencies: [
.package(url: "https://github.com/exyte/SVGView.git")
]
CocoaPods
pod 'SVGView'
Carthage
github "Exyte/SVGView"
Requirements
- iOS 14+ / watchOS 7+ / macOS 11+
- Xcode 12+
Our other open source SwiftUI libraries
PopupView - Toasts and popups library
Grid - The most powerful Grid container
ScalingHeaderScrollView - A scroll view with a sticky header which shrinks as you scroll
AnimatedTabBar - A tabbar with a number of preset animations
MediaPicker - Customizable media picker
Chat - Chat UI framework with fully customizable message cells, input view, and a built-in media picker
OpenAI Wrapper lib for OpenAI REST API
AnimatedGradient - Animated linear gradient
ConcentricOnboarding - Animated onboarding flow
FloatingButton - Floating button menu
ActivityIndicatorView - A number of animated loading indicators
ProgressIndicatorView - A number of animated progress indicators
FlagAndCountryCode - Phone codes and flags for every country
LiquidSwipe - Liquid navigation animation