Swiftpack.co - gualtierofrigerio/ScreenshotSwiftUI as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by gualtierofrigerio.
gualtierofrigerio/ScreenshotSwiftUI 0.3.0
SPM Package to take screenshots of SwiftUI Views
⭐️ 18
🕓 1 year ago
iOS
.package(url: "https://github.com/gualtierofrigerio/ScreenshotSwiftUI.git", from: "0.3.0")

ScreenshotSwiftUI

Add this package via SPM to take screenshots of SwiftUI Views

If you're interested in the details on how it works please refer to my blog post Take screenshot of SwiftUI Views

How it works

The package includes an extension to View called screenshotMaker. Add screenshotMaker to the View you want to take a screenshot of, you'll get a ScreenshotMaker object in the closure and by calling its function screenshot you'll get a UIImage with the screenshot of the View.

import ScreenshotSwiftUI

struct MyView: View 
    var body: some View {
        VStack {
            Text("Hello world")
        }.screenshotMaker { screenshotMaker in 
            let uiImage = screenshotMaker.screenshot()
        }   
    }

Install

The package is distributed via SPM. Include the link below in Xcode to add it to your project.

https://github.com/gualtierofrigerio/ScreenshotSwiftUI.git

GitHub

link
Stars: 18
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics