Skip to content

0.20.1 SwiftUI SVGView

Compare
Choose a tag to compare
@swhitty swhitty released this 23 Feb 11:28
· 43 commits to main since this release
90f94b8

SwiftUI

Adds native SwiftUI support with SVGView:

var body: some View {
    SVGView(named: "sample.svg")
        .aspectRatio(contentMode: .fit)
        .padding()
}

Pass a SVG instance for better performance:

var image: SVG

var body: some View {
    SVGView(svg: image)
}

Transformation

SVG is now a struct and gains the ability to transform the image, updating its size before rasterization:

let svg = SVG(name: "fish.svg")!   // 100x100 
    .expanded(left: 10, right: 10) // 120x100
    .scaled(2)                     // 240x200

imageView.image = svg.rasterize()  // 240x200

Note: @objc(SVGImage) has been removed. SVG is now a struct and incompatible with ObjectiveC. Users can write their own objc wrapper to continue use.