• Stars
    star
    530
  • Rank 80,435 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 3 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SVG parser and renderer written in SwiftUI

     

SVGView

SVG parser written in SwiftUI

SPM Compatible Cocoapods Compatible Carthage Compatible License: MIT

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 pikachu 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
    })
}

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 this page. You can also check out SVGViewTests project 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 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
ConcentricOnboarding - Animated onboarding flow
FloatingButton - Floating button menu
ActivityIndicatorView - A number of animated loading indicators
ProgressIndicatorView - A number of animated progress indicators
LiquidSwipe - Liquid navigation animation

More Repositories

1

Macaw

Powerful and easy-to-use vector graphics Swift library with SVG support
Swift
5,964
star
2

PopupView

Toasts and popups library written with SwiftUI
Swift
2,976
star
3

Grid

The most powerful Grid container missed in SwiftUI
Swift
1,643
star
4

ARTetris

Augmented Reality Tetris made with ARKit and SceneKit
Swift
1,532
star
5

ActivityIndicatorView

A number of preset loading indicators created with SwiftUI
Swift
1,276
star
6

ConcentricOnboarding

SwiftUI library for a walkthrough or onboarding flow with tap actions
Swift
1,242
star
7

FloatingButton

Easily customizable floating button menu created with SwiftUI
Swift
1,010
star
8

ScalingHeaderScrollView

A scroll view with a sticky header which shrinks as you scroll. Written with SwiftUI.
Swift
890
star
9

ReadabilityKit

Preview extractor for news, articles and full-texts in Swift
Swift
829
star
10

fan-menu

Menu with a circular layout based on Macaw
Swift
726
star
11

Chat

A SwiftUI Chat UI framework with fully customizable message cells and a built-in media picker
Swift
561
star
12

LiquidSwipe

Example of using SwiftUI to create a beautiful Liquid Swipe control
Swift
474
star
13

Macaw-Examples

Various usages of the Macaw library
Swift
354
star
14

AnimatedTabBar

A tabbar with a number of preset animations written in pure SwiftUI
Swift
284
star
15

AndroidAnimatedNavigationBar

AnimatedNavigationBar is a navigation bar with a number of preset animations written in Jetpack Compose
Kotlin
263
star
16

MediaPicker

Customizable media picker written with SwiftUI
Swift
255
star
17

replicating

Kotlin
245
star
18

ProgressIndicatorView

An iOS progress indicator view library written in SwiftUI
Swift
200
star
19

ComposeMultiplatformDribbbleAudio

A repo for the Dribbble Replicating Compose Multiplatform article
Kotlin
71
star
20

android-waves-progressbar

A depth gauge progress bar, inspired by Apple Watch dive widget.
Kotlin
41
star
21

clean-swift-article

Swift
37
star
22

sweet.eclipse

Sweet Eclipse
HTML
33
star
23

gaster

Ethereum transactions stats for your smart contracts
JavaScript
30
star
24

FlagAndCountryCode

A country code and flag icon provider library for iOS apps
Swift
28
star
25

android-replicating

Replicating complex UI using Jetpack Compose
Kotlin
23
star
26

ShapedBackgroundAndroid

Repo for the instagram-like shaped background on Android
Kotlin
23
star
27

wwdc2020-tutorials

Swift
21
star
28

AnimatedGradient

Swift
18
star
29

core-haptics-example

Swift
13
star
30

homebrew-formulae

Ruby
1
star
31

openai-assistants-api

Swift
1
star