Last active
May 5, 2023 17:35
-
-
Save andresr-dev/373bc550d88893ec91af9b0186825b06 to your computer and use it in GitHub Desktop.
This is how to convert a SwiftUI View to Base 64 format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct SwiftUIToBase64View: View { | |
@Environment(\.displayScale) var displayScale | |
var body: some View { | |
Text("Hello, World!") | |
} | |
@MainActor private func ecode() -> String? { | |
let renderer = ImageRenderer(content: Text("Hello")) | |
// Make sure to use the correct display scale for this device, so that the image can render with good resolution. | |
renderer.scale = displayScale | |
return renderer.uiImage?.jpegData(compressionQuality: 1.0)?.base64EncodedString() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment