ConsoleUI icon indicating copy to clipboard operation
ConsoleUI copied to clipboard

Discussion

Open L1cardo opened this issue 5 years ago • 2 comments

I found a way to rasterize views to images directly using a button.

For example: If you just do this, it will not work. Because the text is ""

@State private var text = ""

Button("rasterize") {
    Text(text).rasterize()
}

But here is the tricky part, you can change the @State text in another view and pass it by @Binding

//first view
@State private var text = ""

Button("rasterize") {
    Text(text).rasterize()
}

// second view
@Binding var text: String

TextField("Change the text here", text: $text)

I don't know if there is better way to do this, and I made an app.

屏幕录制2020-07-20 下午7 38 05 2020-07-20 19_40_13

L1cardo avatar Jul 20 '20 11:07 L1cardo

I cannot believe I didn't see this comment until today. Supper happy to see what you made. Did you ever release the app to the App Store?

eneko avatar Apr 22 '22 03:04 eneko

It is really tricky in SwiftUI to make a view into image. This is the project shown on the gif, this is a self-use-only project, codes are very rough. https://github.com/L1cardo/AppShot

L1cardo avatar Apr 22 '22 15:04 L1cardo