All Projects → pocketsvg → Pocketsvg

pocketsvg / Pocketsvg

Licence: mit
Easily convert your SVG files into CGPaths, CAShapeLayers, and UIBezierPaths

Programming Languages

swift
15916 projects
Objective-C++
1391 projects
objective c
16641 projects - #2 most used programming language
shell
77523 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Pocketsvg

Simple Icons
SVG icons for popular brands
Stars: ✭ 12,090 (+715.24%)
Mutual labels:  svg, svg-files
Ihequalizerview
An Custom UIView which draws the output of an audio asset in real time.
Stars: ✭ 106 (-92.85%)
Mutual labels:  cocoapods
Sdwebimagewebpcoder
A WebP coder plugin for SDWebImage, use libwebp
Stars: ✭ 101 (-93.19%)
Mutual labels:  cocoapods
Sparse
Sparse is a simple parser-combinator library written in Swift.
Stars: ✭ 104 (-92.99%)
Mutual labels:  cocoapods
React Feather
React component for Feather icons
Stars: ✭ 1,379 (-7.01%)
Mutual labels:  svg
Rxviz
Rx Visualizer - Animated playground for Rx Observables
Stars: ✭ 1,471 (-0.81%)
Mutual labels:  svg
Grawkit
The Awksome Git Graph Generator
Stars: ✭ 101 (-93.19%)
Mutual labels:  svg
Buckets Swift
Swift Collection Data Structures Library
Stars: ✭ 106 (-92.85%)
Mutual labels:  cocoapods
React Native Responsive Linechart
A customizable and responsive line or area chart for react-native
Stars: ✭ 105 (-92.92%)
Mutual labels:  svg
Conf
Landing page for event React Conf Brazil
Stars: ✭ 104 (-92.99%)
Mutual labels:  svg
I7j Pdfhtml
pdfHTML is an iText 7 add-on for Java that allows you to easily convert HTML and CSS into standards compliant PDFs that are accessible, searchable and usable for indexing.
Stars: ✭ 104 (-92.99%)
Mutual labels:  svg
Datepicker
A Date Picker with Calendar for iPhone and iPad Apps.
Stars: ✭ 103 (-93.05%)
Mutual labels:  cocoapods
Ccnpreferenceswindowcontroller
CCNPreferencesWindowController is an Objective-C subclass of NSWindowController that automatically manages your custom view controllers for handling app preferences.
Stars: ✭ 105 (-92.92%)
Mutual labels:  cocoapods
Rdgliderviewcontroller Swift
Control for a floating view gliding over a ViewController Edit
Stars: ✭ 102 (-93.12%)
Mutual labels:  cocoapods
D3 Tube Map
Draw tube maps in the style of the London Underground using d3
Stars: ✭ 106 (-92.85%)
Mutual labels:  svg
Openmoji
Open source emojis for designers, developers and everyone else!
Stars: ✭ 1,380 (-6.95%)
Mutual labels:  svg
Tkdotsegment
TKDotSegment is a segment with dot animation
Stars: ✭ 103 (-93.05%)
Mutual labels:  cocoapods
Vue Svg Inline Loader
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
Stars: ✭ 105 (-92.92%)
Mutual labels:  svg
Elephant
Elegant SVG animation kit for swift
Stars: ✭ 107 (-92.78%)
Mutual labels:  svg
Reimg
reimg - A javascript library for converting image formats
Stars: ✭ 106 (-92.85%)
Mutual labels:  svg

PocketSVG

Platforms Build Status Swift Package Manager CocoaPods Compatible Carthage compatible Code Coverage code size license Swift Forums

A simple toolkit for displaying and manipulating SVGs on iOS and macOS in a performant manner.

The goal of this project is not to be a fully compliant SVG parser/renderer. But rather to use SVG as a format for serializing CG/UIPaths, meaning it only supports SVG features that can be represented by CG/UIPaths.

Thoroughly documented.

Features

  • Support for SVG elements: path, line, polyline, polygon, rect, circle, ellipse
  • Support for SVG named colors.
  • Fully working iOS and macOS demos.
  • Straightforward API for typical SVG rendering as a UIImageView/NSImageView or CALayer subclass.
  • Access every shape within your SVG as a CGPath for more fine-grained manipulation.

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/pocketsvg/PocketSVG.git", .upToNextMajor(from: "2.6.0"))
]

Cocoapods

Add this to your Podfile:

pod 'PocketSVG', '~> 2.6'

Then run pod install

Carthage

Add this to your Cartfile:

github "pocketsvg/PocketSVG" ~> 2.6

Then run carthage update

Usage

Render an SVG file using SVGImageView

let url = Bundle.main.url(forResource: "tiger", withExtension: "svg")!
let svgImageView = SVGImageView.init(contentsOf: url)
svgImageView.frame = view.bounds
svgImageView.contentMode = .scaleAspectFit
view.addSubview(svgImageView)

Output image

Note: By default, SVGLayer has shouldRasterize set to YES when running on iOS. If you need to animate changes to the layer's transform you might want to reset that to NO.

Manually render each path of an SVG file using CAShapeLayer

view.backgroundColor = .white

let svgURL = Bundle.main.url(forResource: "tiger", withExtension: "svg")!
let paths = SVGBezierPath.pathsFromSVG(at: svgURL)
let tigerLayer = CALayer()
for (index, path) in paths.enumerated() {
    let shapeLayer = CAShapeLayer()
    shapeLayer.path = path.cgPath
    if index%2 == 0 {
        shapeLayer.fillColor = UIColor.black.cgColor
    }
    else if index%3 == 0 {
        shapeLayer.fillColor = UIColor.darkGray.cgColor
    }
    else {
        shapeLayer.fillColor = UIColor.gray.cgColor
    }
    tigerLayer.addSublayer(shapeLayer)
}

var transform = CATransform3DMakeScale(0.4, 0.4, 1.0)
transform = CATransform3DTranslate(transform, 200, 400, 0)
tigerLayer.transform = transform
view.layer.addSublayer(tigerLayer)

Output image

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

PRs are welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].