SVG parser and renderer written in SwiftUI

Related tags

Graphics SVGView
Overview

SVGView

SVG parser written in SwiftUI


We are a development agency building phenomenal apps.




Travis CI Version Carthage Compatible License Platform Twitter

Overview

The goal of this project is to bring the full power of SVG to Apple platforms. Out 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(fileURL: Bundle.main.url(forResource: "example", withExtension: "svg")!)
    }
}

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(fileURL: 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 stanard 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(fileURL: 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

CocoaPods

pod 'SVGView'

Carthage

github "Exyte/SVGView"

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/exyte/SVGView.git", from: "1.0.0")
]

Requirements

  • iOS 13+ / watchOS 13+ / tvOS 13+ / macOS 11+
  • Xcode 11+
Comments
  • Resizing issue

    Resizing issue

    Hi,

    I'm having a resizing issue with the library. Depending on the svg file I use, I get an image correctly displayed, or I get an image taking way much space than it should (ie more space than the screen itself).

    To display the svg file, I'm using this:

    SVGView(fileURL: svgFilePath)
            .scaledToFit()
            .frame(width: 200, height: 200)
    

    From what I've seen, the svg files that are defined with a large width and height are not displayed correctly, which maybe makes sense. But shouldn't svg images be stretched as we want?

    opened by SoreGaInochi 10
  • Font is always the same size.

    Font is always the same size.

    When I render an svgs, the font is always the same size. I have a number of svgs images that have fonts of different size in them, but when rendered with SVGView, they are all the same size. Below are a couple of pictures from an example.

    What the svgs should actually look like. Screen Shot 2022-05-25 at 4 35 24 AM

    What the svgs looks like with SVGView. Screen Shot 2022-05-25 at 4 36 44 AM

    Here is the actual svgs file that I used for this example. FontExample

    opened by littlethormanator 3
  • Fix SwiftPM build

    Fix SwiftPM build

    • NSRegularExpression can't be resolved unless the Foundation import is added
    • iOS 14 is required because of Color.cgColor
    • Info.plist is explicitly excluded to suppress an error message that it is unaccounted for
    opened by PhilipTrauner 3
  • Add `import Combine` to all files which uses @Published

    Add `import Combine` to all files which uses @Published

    @Published is a part of Combine, not importing Combine everywhere its used will cause a Unknown attribute 'Combine.Published' when compiled as a XCFramework.

    This PR adds import Combine to all relevant files.

    opened by sampettersson 1
  • Fixed duplication of gestures in makeOneGesture

    Fixed duplication of gestures in makeOneGesture

    The implementation of View.makeOneGesture() in 1.0.4 has a bug which results in duplication of gestures when only one Gesture has been added to the view.

    The impact of this bug can be observed with the following sample code:

    @State var isEnabled: Bool = true
    let logger = Logger()
    
    if let part = view.getNode(byId: "part") {
        part.onTapGesture {
           isEnabled.toggle()
           logger.debug("isEnabled = \(isEnabled)")
        }
    }
    

    Tapping on the node once will cause the code block to execute twice; in the above example, this sets isEnabled to true and then false.

    This PR adds a guard to abort creating a SimultaneousGesture if only one gesture exists.

    opened by rstrahl 0
  • Text is not displayed on the SVGView

    Text is not displayed on the SVGView

    My Code here:

    
    import SwiftUI
    import SVGView
    
    struct ContentView: View {
        @State private var data: Data?
        
        var body: some View {
            if let data {
                SVGView(data: data)
            } else {
                Color.black.opacity(0.001)
                    .task {
                        if let (data, _) = try? await URLSession.shared.data(from: URL(string: "https://img.shields.io/cocoapods/l/SVGView.svg?style=flat")!) {
                            self.data = data
                        }
                    }
            }
        }
    }
    

    I use the one in your README.md file, and this is( I guess ) a SVG, but SVGView can only show the background but no text on it.

    截屏2022-10-16 16 50 49
    opened by LiYanan2004 0
  • Are embeeded images supported?

    Are embeeded images supported?

    I am rendering an svg with an embedded image and it does not render. I tried also adding the image with a remote url and it also does not render. I can see it render correctly in xcode preview though.

    Thanks in advance.

    opened by txbrown 0
  • Make view resizable

    Make view resizable

    Right now in SVGDataImage and SVGURLImage I see modifier .frame(width: model.width, height: model.height), so image always this this size, I suggest replace it with resizable() modifier to let user to set image size

    opened by dankinsoid 0
  • Allow opacity key in stylesheet to update fill and stroke opacities

    Allow opacity key in stylesheet to update fill and stroke opacities

    In the stylesheet of an SVG, we can have opacity, fill-opacity, and stroke-opacity. When opacity is used, it should affect both fill and stroke if fill-opacity and stroke-opacity are absent. Previously SVGView only supported fill-opacity and stroke-opacity from the stylesheet but not opacity.

    Also added a sample SVG file to demonstrate that, and included it in the unit test.

    opened by ba01ei 0
Owner
Exyte
Exyte
Display and interact with SVG Images on iOS / OS X, using native rendering (CoreAnimation)

SVGKit SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. Some additional info and links are on the wiki Versions:

null 4.3k Jan 3, 2023
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Exyte 5.9k Jan 2, 2023
❄️ SVG in Swift

Snowflake ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut ma

Khoa 949 Dec 14, 2022
A super easy way to check if the installed app has an update available. It is built with simplicity and customisability in mind and comes with pre-written tests.

UpdateAvailableKit This is UpdateAvailableKit: a super easy way to check if the installed app has an update available. It is built with simplicity and

Swapnanil Dhol 22 Jan 5, 2023
A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.

Overview Description Requirements Installation Usage Author License Description XMLParser lets you convert a pure Swift dictionary into XML string and

Eugene Mozharovsky 75 Feb 2, 2022
QEMU-Manager is a macOS graphical frontend to QEMU, written in Swift.

QEMU-Manager About QEMU-Manager is a macOS graphical frontend to QEMU, written in Swift. Screenshots General Configuration: Hardware Configuration: Di

Jean-David Gadina 212 Jan 6, 2023
Conical (angular) gradient for iOS written in Swift

AEConicalGradient Conical (angular) gradient in Swift I hope that somebody will find this useful. And nice. Usage AEConicalGradient is a minion which

Marko Tadić 82 Dec 27, 2022
Create Live Graphics in SwiftUI (iOS, tvOS & macOS)

PixelUI import SwiftUI import PixelUI struct ContentView: View { var body: some View { GeometryReader { geo in

Anton Heestand 21 Dec 17, 2022
Drawing and Geometry made easy on iOS - now in Swift 3.0

InkKit Swift Support Swift 4.0 InkKit is Swift 4.0 by default, so to use that just include InkKit in your podfile: pod 'InkKit' Swift 3.2 In order to

Shaps 373 Dec 27, 2022
iOS utility classes for asynchronous rendering and display.

YYAsyncLayer iOS utility classes for asynchronous rendering and display. (It was used by YYText) Simple Usage @interface YYLabel : UIView @property NS

null 672 Dec 27, 2022
NXDrawKit is a simple and easy but useful drawing kit for iPhone

⚠️ To use with Swift 5.0 please ensure you are using >= 0.8.0 ⚠️ ⚠️ To use with Swift 4.2 please ensure you are using >= 0.7.1 ⚠️ ⚠️ To use with Swift

Nicejinux 1.3k Dec 31, 2022
An iOS framework for easily adding drawings and text to images.

jot is an easy way to add touch-controlled drawings and text to images in your iOS app. What's jot for? Annotating Images jot is the easiest way to ad

IFTTT 1.8k Oct 28, 2022
Create gradients and blur gradients without a single line of code

EZYGradientView is a different and unique take on creating gradients and gradients with blur on the iOS platform. The default CAGradientLayer implemen

Shashank Pali 380 Dec 6, 2022
The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo erase the drawing.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Haresh 0 Oct 28, 2021
When you scan the clothing tag, a 3D character appears and informs you of the clothing information.

1. Introduction When you scan the clothing tag, a 3D character appears and tells you the information on the clothes. You can select necessary informat

kimniki 0 Dec 23, 2021
3D Touch Application for Weighing Plums (and other small fruit!)

Plum-O-Meter ###3D Touch Application for Weighing Plums (and other small fruit!) Companion project to this blog post: http://flexmonkey.blogspot.co.uk

simon gladman 526 Sep 27, 2022
SVG-Native (SVG OpenType) image coder plugin for SDWebImage

SDWebImageSVGNativeCoder Background Currently SDWebImage org provide 3 kinds of SVG Coder Plugin support, here is comparison: Plugin Name Vector Image

null 5 Dec 23, 2022
A simple, performant, and lightweight SVG parser

Key Features Parsing performance that meets or beats other popular SVG Frameworks A simple architecture, optimized for extension, flexibility and deve

Michael Choe 1.8k Dec 29, 2022
A simple, performant, and lightweight SVG parser

Key Features Parsing performance that meets or beats other popular SVG Frameworks A simple architecture, optimized for extension, flexibility and deve

Michael Choe 1.8k Dec 29, 2022
A lightweight 3D renderer for SwiftUI.

Prism A lightweight 3D renderer for SwiftUI. Works with any SwiftUI View. Fully interactive and animatable. Compatible with all SwiftUI modifiers. Wil

Andrew Zheng 700 Dec 24, 2022