Skip to content

SwiftUI 轻量级自定义截图组件 / A SwiftUI View can easily get a custom screenshot image.

License

Notifications You must be signed in to change notification settings

RickeyBoy/ScreenshotableView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Feb 24, 2025
4085331 · Feb 24, 2025

History

19 Commits
Feb 24, 2025
Jul 2, 2024
Feb 24, 2025
Jul 2, 2024
Jul 19, 2023
Jul 2, 2024
Jul 19, 2023
Jul 19, 2023
Jul 2, 2024
Jul 2, 2024

Repository files navigation

ScreenshotableView

A View in SwiftUI that supports custom screenshot functionality.

中文说明

🌄 Functionality Preview

Download example project and try it!!

💻 Usage Instructions

You can also directly use the Example project for reference.

  1. Screenshot

Directly use the provided ScreenshotableView with screenshot:

ScreenshotableView(shotting: $shotting) { screenshot in
    // Return the screenshot image
} content: { style in
    // Set the View content
    Content(style: style)
}

Also supports capturing all content within a ScrollView as a long image, by using ScreenshotableScrollView.

ScreenshotableScrollView(shotting: $shotting) { screenshot in
    // Return the screenshot image
} content: { style in
    // No need to nest ScrollView for the content within ScrollView
    Content(style: style)
}
  1. Customize the View content:

There are two styles for ScreenshotableViewStyle: inView and inScreenshot. You can adjust the UI style for normal display and when taking a screenshot based on the style.

@ViewBuilder
func Content(style: ScreenshotableViewStyle) -> some View {
    content // View content
        // Adjust the corner radius based on the style
        // For example, here the corner radius is 4 for normal display and 10 for screenshots
        .cornerRadius(style == .inView ? 4 : 10)
}
  1. Call when you need to take a screenshot:
shotting.toggle()

🛠 Adding to Your Project Using Swift Package Manager

In Xcode, go to File > Swift Packages > Add Package Dependency..., then enter https://github.com/RickeyBoy/ScreenshotableView to search and add it.

About

SwiftUI 轻量级自定义截图组件 / A SwiftUI View can easily get a custom screenshot image.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages