• Stars
    star
    956
  • Rank 45,921 (Top 1.0 %)
  • Language
    Swift
  • License
    Other
  • Created over 7 years ago
  • Updated 5 months ago

Reviews

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

Repository Details

❄️ SVG in Swift

Snowflake

Buy Me A Coffee

Checkout https://indiegoodies.com/

Version Carthage Compatible License Platform Swift

Description

  • SVG in Swift
  • Use XML parser from Reindeer

Usage

Document

  • Create a Document with SVG Data
guard let path = Bundle.main.path(forResource: "xmas", ofType: "svg"),
  let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
   let document = Snowflake.Document(data: data)
 else { return }

let view = document.svg.view(size: CGSize(width: 100, height: 100))

  • The flow is SVG element -> Shape -> UIBezierPath -> CALayer
  • Make Shape from attributes
let attributes: [String: Any] = [
  "fill": "#358245",
  "stroke": "black",
  "stroke-miterlimit": "10",
  "d": "M308.3,102.3c4.5,8.2,9,16.2,13.2,24.3c7.2,13.9,15.8,26.9,25.6,39c10.1,12.4,21.5,23.6,33.6,34.1c2.5,2.1,5.2,3.9,8.1,6c-5.1,3.5-11.2,3.8-17,4.2c-11.9,0.9-23.7,1.5-36.4,2.3c22.7,46.7,59.7,74.6,109.7,88.1c-4.2,3.8-7.7,7.4-11.7,10.4c-11.3,8.6-24.4,13.7-38,17.4c-10.1,2.8-20.3,5-31.3,7.7c3.2,5,5.8,10.2,9.5,14.7c6.9,8.5,14.1,16.9,21.7,24.7c12.5,12.9,27.3,23,43.2,31c17.5,8.8,35.5,16.7,53.8,25.2c-3.4,3.1-6.9,7.1-11.2,10.1c-17,12.1-36.1,19.4-56.4,23.8c-8.7,1.9-17.3,3.7-27.5,5.8c5,4.7,9,9.2,13.7,12.6c13.2,9.4,26.4,19,40.4,27.1c11.8,6.9,24.6,12.1,37.3,17.4c10.4,4.3,21.1,7.7,31.7,11.5c1.1,0.4,2.3,0.5,4.4,0.9c-2.1,2.6-3.5,5.3-5.7,7c-6.7,5.3-13.2,10.8-20.5,15.1c-14.8,8.7-30.5,15.6-47.5,19.2c-17.8,3.8-35.6,3.1-53.3-0.8c-18.1-3.9-35.4-10.3-52.6-16.8c-5.7-2.2-11.7-3.7-17.5-5.8c-2.8-1-3.9,0.1-4.2,2.7c-1.1,11.3,2.7,22.1,15.6,22.4c2,0.1,3.9,0.6,5.9,0.7c6,0.3,8.7,3.1,7.7,9.1c-2,12.5-4.4,25-6.6,37.6c-2.6,14.6-5.1,29.2-7.6,43.8c-0.3,2-1.1,2.9-3.3,2.9c-17.2-0.1-34.4,0-51.6-0.1c-2.2,0-4.4-0.5-7-0.7c-1.2-6.4-2.4-12.8-3.5-19.2c-3.5-20.7-7-41.3-10.5-62c-1.8-10.5-1-9.6,8.8-11.5c4.4-0.8,9.1-1.5,13.1-3.5c5.8-2.9,8.8-15.1,6.1-21.1c-1-2.3-2.4-1.9-4.1-1.3c-10.5,3.9-21.1,7.8-31.6,11.8c-20.4,7.7-41.2,12.9-63.3,13.6c-26.3,0.8-49.9-6.4-72.4-18.8c-11.1-6.2-21.7-13.3-32.3-20.6c47.5-18,93.7-37,131.4-73.8c-35.8-5.2-68-17.1-97.8-38.3c5.2-2.4,9.3-4.5,13.6-6.1c26.2-9.7,50.5-23,72.6-40c17.5-13.4,32.1-29.6,43.7-48.5c0.3-0.4,0.4-0.9,0.6-1.5c-13.9-4-27.8-7.4-41.3-12.1c-13.5-4.7-26.3-11-37.1-22.2c4.8-2.1,9.1-4.3,13.5-6c19.2-7.5,36.9-17.5,52.4-31.2c15.1-13.4,27.5-29.1,38.1-46.2c0.7-1.1,1.3-2.3,1.9-3.5c0.5-1.2,1-2.4,1.5-3.9c-17.9-2.9-36.2,1.7-54.4-4.8c18.9-13.7,34.9-28.9,47.3-47.3C285.1,140.7,296.2,121.7,308.3,102.3z"
]

let path = Path(attributes: attributes)
let layer = path.layer

Shapes

  • The Shape object maps to SVG elements

    • path: Path
    • circle: Circle
    • line: Line
    • polygon: Polygon
    • polyline: Polyline
    • rect: Rectangle
    • ellipse: Ellipse
    • text: Text
    • image: Image
  • Path handles list of commands through Command object

Style

  • The Style object encapsulates style information
let attributes: [String: Any] = [
  "fill": "lime",
  "stroke": "purple",
  "stroke-width": "5",
  "fill-rule": "evenodd"
]

let style = Style(attributes: attributes)
  • Inner style
<polygon points="100,10 40,198 190,78 10,78 160,198" fill="lime" stroke="purple" stroke-width="5" fill-rule="evenodd" />
  • Style attribute
<polygon points="100,10 40,198 190,78 10,78 160,198" style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />

Animation

  • The cool thing about CALayer is that most of its properties are animatable
(svgView.layer.sublayers as? [CAShapeLayer])?.forEach { layer in
  let stroke = CABasicAnimation(keyPath: "strokeEnd")
  stroke.fromValue = 0
  stroke.toValue = 1
  stroke.duration = 3

  layer.add(stroke, forKey: nil)
}

Scale

  • Scale layers to a given size
let layers = document.svg.layers(size: CGSize(width: 200, height: 100))
  • Scale view to a given size
let view = document.svg.view(size: CGSize(width: 100, height: 100))

Text

  • TBD

Image

let attributes: [String: Any] = [
  "x": "0",
  "y": "y",
  "width": "100",
  "height": "100",
  "href": "data:image/png;base64,..."
]

let image = Image(attributes: attributes)

Pattern

  • TBD

Installation

Snowflake is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Snowflake', git: 'https://github.com/onmyway133/Snowflake'

or

pod 'FantasticSnowflake'

Snowflake is also available through Carthage. To install just write into your Cartfile:

github "onmyway133/Snowflake"

Snowflake can also be installed manually. Just download and drop Sources folders in your project.

Author

Khoa Pham, [email protected]

Contributing

We would love you to contribute to Snowflake, check the CONTRIBUTING file for more info.

License

Snowflake is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

awesome-ios-animation

☔ A collection of iOS animation repos
5,305
star
2

awesome-ios-architecture

🏯 Better ways to structure iOS apps
5,056
star
3

PushNotifications

🐉 A macOS, Linux, Windows app to test push notifications on iOS and Android
JavaScript
2,230
star
4

DeepDiff

🦀Amazingly incredible extraordinary lightning fast diffing in Swift
Swift
2,049
star
5

IconGenerator

🍱 A macOS app to generate app icons
JavaScript
1,403
star
6

RoughSwift

🎃 Create hand-drawn, sketchy, comic shape in Swift
Swift
1,104
star
7

FinderGo

🐢 Open terminal quickly from Finder
Swift
1,084
star
8

GifCapture

🏇 Gif capture app for macOS
Swift
916
star
9

awesome-machine-learning

🎰 A curated list of machine learning resources, preferably CoreML
794
star
10

Swiftlane

🚀 Build utilities in pure Swift
Swift
691
star
11

blog

🍁 What you don't know is what you haven't learned
666
star
12

awesome-swiftui

🌮 Awesome resources, articles, libraries about SwiftUI
642
star
13

EasyConfetti

🎊 Fancy confetti effects in Swift
Swift
561
star
14

XcodeWay

⛵ An Xcode Source Editor Extension that helps navigating to many places easier
Swift
550
star
15

Smile

😄 Emoji in Swift
Swift
512
star
16

EasyAnchor

⚓️ Declarative, extensible, powerful Auto Layout
Swift
455
star
17

EasyStash

🗳Easy data persistence in Swift
Swift
377
star
18

Scale

🎏 Unit converter in Swift
Swift
323
star
19

EasyDropdown

💧 Fantastic dropdown in Swift
Swift
309
star
20

XcodeColorSense2

🍉 An Xcode source editor extension that shows hex color info
Swift
285
star
21

Arcane

🔱 CommonCrypto in Swift, and more
Swift
283
star
22

awesome-android-animation

💦 A collection of Android animation repos
Java
253
star
23

EasyTheme

👕👚 Theme management in Swift
Swift
241
star
24

awesome-voip

🤙Learning VoIP, RTP, pjsip and SIP
237
star
25

SwiftHash

🍕 MD5 in pure Swift
Swift
215
star
26

EasyClosure

🍩 Unified communication patterns with easy closure in Swift
Swift
201
star
27

Github.swift

:octocat: Unofficial GitHub API client in Swift
Swift
186
star
28

emoji

❤️ List of emojis
Swift
163
star
29

SwiftSnippets

🍮 A collection of Swift snippets to be used in Xcode
Shell
162
star
30

Wave

🌊 Declarative chainable animations in Swift
Swift
127
star
31

awesome-online-earning

💰Ways to earn extra
124
star
32

Spek

🎏 Function builder BDD testing framework in Swift
Swift
122
star
33

FontAwesomeSwiftUI

Easy to use FontAwesome 5 in SwiftUI
Swift
97
star
34

Recipes

🍣Making Recipes iOS app
Swift
91
star
35

MathSolver

⌨️Camera calculator with Vision
Swift
87
star
36

XcodeColorSense

🎈 An Xcode plugin that makes working with color easier
Swift
77
star
37

Micro

🏎Fast diffing and type safe SwiftUI style data source for UICollectionView
Swift
76
star
38

Omnia

🗿 Everything your projects need to know
Swift
62
star
39

notes

📔 Issues and solutions I found during development, mostly iOS
62
star
40

Sketch-Action

🔎 A Sketch plugin to simulate Spotlight
Objective-C
59
star
41

MainThreadGuard

💂‍♂️ Tracking UIKit access on main thread
Swift
58
star
42

EasyFake

🤹‍♀️ Fake data generation in Swift
JavaScript
57
star
43

Reindeers

❄️ XML and HTML parser in Swift
Swift
55
star
44

awesome-git-commands

🍴 Indispensable git commands for everyday use
55
star
45

RxLifeCycle

🐹 Easy life cycle observation
Swift
53
star
46

Upstream

⛲️ Adapted Data Source in Swift and a little bit more
Swift
53
star
47

BigBigNumbers

🔢Say the number out loud
Swift
49
star
48

GifMagic

💈 Gif maker and extractor in Swift
Swift
48
star
49

awesome-android-architecture

🏰 Better ways to structure Android apps
45
star
50

AppStoreConnect

🍎 Interact with AppStoreConnect
Swift
45
star
51

TestTarget

🐳 Notes on configuring test targets
Swift
44
star
52

PhotoFeed

🛵 Instagram in Swift 4
Swift
43
star
53

awesome-conference-videos

🎸 Conference videos. Visit http://learntalks.com/
40
star
54

CollectionUpdateExample

🛶 Demo batch update in UITableView and UICollectionView
Swift
38
star
55

Construction

👷 The many ways to construct and configure your entity
Swift
34
star
56

PastePal

PastePal is the best universal clipboard manager for Mac, iPhone and iPad.
31
star
57

github-extended

:octocat: A Chrome extension to discover more repositories
JavaScript
30
star
58

EasyNetworking

🛰Easy networking with async/await
Swift
28
star
59

Runtime-Headers

💿 iOS, macOS runtime headers
Objective-C
28
star
60

UsingPlayground

👶 Demo how to use Playground
Swift
26
star
61

EasySwiftUI

🍰 Extra sugar for SwiftUI
Swift
25
star
62

Farge

🎈Tell the name of hex color
Swift
24
star
63

Avengers

👾Demo how to use CoreML with IBM Watson, Azure Custom Vision, Turi Create
Swift
21
star
64

ISO8601

🎗 Super lightweight ISO8601 Date Formatter in Swift
Swift
21
star
65

SlidingMenu

🎿 Demo how to create sliding menu on Android
Java
20
star
66

Paramount

🗼 Like Flipboard FLEX, but allows custom action
Swift
20
star
67

Codelime

Codelime is a powerful code snippet manager with many dev tools for iOS development.
19
star
68

DynamicTableViewCellHeight

🍟 Demo how to use Autolayout to make varying row height
Objective-C
18
star
69

github-chat

💬 A Chrome extension to enable chat within GitHub
JavaScript
18
star
70

Resolver

🎊 A simple resolver in Swift
Swift
15
star
71

archives

🚣 Only deliberate practice will make you better
Objective-C
14
star
72

ParticlePlayground

🎊 A Swift playground to play with CAEmitterLayer
Swift
14
star
73

json_resolve

🐰Easy resolving deep json using keypath in Dart
Dart
12
star
74

Then

🏃 Promise A+ in Swift
Swift
11
star
75

LighterAppDelegate

🎣 Lighter AppDelegate by dispatching events
Swift
10
star
76

Xkcd

🦄 Simple Xkcd iOS app
Swift
8
star
77

Border

📐 Make border for all views
Swift
8
star
78

github-changelogs-maker

🍻 Generate changelogs between 2 latest releases
JavaScript
7
star
79

Xmas

🎅 🎄 ⛄ Xmas plugin for Xcode
Objective-C
7
star
80

linphone-iphone

Forked from linphone.org
Objective-C
7
star
81

EasyTracker

🕵️ Trackers in Swift
Swift
6
star
82

FantasticDisplay

🎢 Fantastic HUD and toast in Swift
Swift
6
star
83

ComputerScienceSwift

👨‍💻 Practice computer science in Swift
Swift
6
star
84

PushHero

Push Hero is a native macOS application written in pure Swift that allows us to easily test push notifications
6
star
85

onmyway133

What you don't know is what you haven't learned
5
star
86

Minion

🐝 Working with Xcode plugins
Swift
5
star
87

SketchHeaders

💿 Headers from Sketch
Objective-C
4
star
88

homebrew-formulae

🚗 Homebrew formulae
Ruby
3
star
89

DarkSide

🌌 My dark theme based on Atom One Dark
Shell
3
star
90

chat_webrtc

⌨️ Simple chat application using Node.js and WebRTC Data Channel
JavaScript
3
star
91

slackbot-yoda

💍 Slackbot Yoda
JavaScript
2
star
92

onmyway133.github.io

Showcase
HTML
2
star
93

rtpproxy

🥂 Forked from http://www.rtpproxy.org/ with IP handover support
C
2
star
94

android-architecture-components-kotlin

🥋 Samples for Android Architecture Components in Kotlin
Kotlin
2
star
95

traffic_simulator

🚗 Traffic simulator using enchant.js
JavaScript
2
star
96

Shipmunk

Search, bookmark and track keyword rating for your favorite apps
2
star
97

Dust

🚀 Unofficial, simple push notification
Swift
1
star
98

MarqueeTextBlock

🌴 How to make marquee TextBlock on Windows Phone
C#
1
star