- SVG in Swift
- Use XML parser from Reindeer
- Create a
Document
with SVGData
guard let path = Bundle.main.path(forResource: item, ofType: "svg"),
let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
let document = Snowflake.Document(data: data)
else { return }
let view = document.svg.view
- The flow is
SVG element
->Shape
->CALayer
-
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:
-
PathShape
handles list of commands throughCommand
object
- The
Style
object encapsulates style information
- 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;" />
- The cool thing about
CALayer
is that most of its properties are animatable
let layer = PathShape().layer
let animator = Animator()
animator.animate(layer: layer)
- TBD
- TBD
Snowflake is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Reindeer', git: 'https://github.com/onmyway133/Reindeer'
pod 'Snowflake', git: 'https://github.com/onmyway133/Snowflake'
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.
Khoa Pham, [email protected]
We would love you to contribute to Snowflake, check the CONTRIBUTING file for more info.
Snowflake is available under the MIT license. See the LICENSE file for more info.