-
I'm now trying to make a ShareLink for the QR-code, but anything I try just doesn't seem to work :( So all I need is code for a ShareLink with this exact QR-code generator, thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
@vicvoh What is it you’re trying to share? The image of a QR code, or the QR code definition? can you please describe exactly what it is you’re trying to do/share? What’s the use case? |
Beta Was this translation helpful? Give feedback.
-
@vicvoh You can use the library to generate an image of the QR code and then use the ShareLink to share the image? import SwiftUI
import QRCode
struct ContentView: View {
let doc = QRCode.Document()
var body: some View {
NavigationStack {
QRCodeDocumentUIView(document: doc)
.padding()
.toolbar {
let qrImage = try! doc.imageUI(CGSize(width: 600, height: 600), label: Text("My QR Code"))
ShareLink(
item: qrImage,
preview: SharePreview("My QR Code", image: qrImage)
)
}
}
}
}
#Preview {
ContentView()
} |
Beta Was this translation helpful? Give feedback.
-
Thank you for the code, it's working nice, but let's say the user has just styled their QR-code, and they want to share it. To style the QR-code, I'm using your |
Beta Was this translation helpful? Give feedback.
-
func generateQRCode(data: String) -> Data? {
let filter = CIFilter.qrCodeGenerator()
guard let data = data.data(using: .ascii, allowLossyConversion: false) else { return nil }
filter.message = data
guard let ciimage = filter.outputImage else { return nil }
let transform = CGAffineTransform(scaleX: 16, y: 16)
let scaledCIImage = ciimage.transformed(by: transform)
let uiimage = UIImage(ciImage: scaledCIImage)
return uiimage.pngData()!
} This is the old QR-code generator I used, but it was really bad, since it didn't have any styling and no support for other languages. |
Beta Was this translation helpful? Give feedback.
-
It already has many functions for this on the QRCode.Document object for exporting images, jpeg, png, svg, pdf and vector types. https://github.com/dagronf/QRCode?tab=readme-ov-file#generating-a-styled-image Look at the examples given in the documentation for generating image data from a qr code https://github.com/dagronf/QRCode?tab=readme-ov-file#styling-your-qr-code The documentation also gives examples of the more modern 'builder' style interface for easily generating an image https://github.com/dagronf/QRCode?tab=readme-ov-file#qrcode-builder Also there are plenty of real-world examples of building qr code images in the |
Beta Was this translation helpful? Give feedback.
It already has many functions for this on the QRCode.Document object for exporting images, jpeg, png, svg, pdf and vector types.
https://github.com/dagronf/QRCode?tab=readme-ov-file#generating-a-styled-image
Look at the examples given in the documentation for generating image data from a qr code
https://github.com/dagronf/QRCode?tab=readme-ov-file#styling-your-qr-code
The documentation also gives examples of the more modern 'builder' style interface for easily generating an image
https://github.com/dagronf/QRCode?tab=readme-ov-file#qrcode-builder
Also there are plenty of real-world examples of building qr code images in the
Examples
subfolderhttps://github.com/dagronf/QRCode/tree/main/Ex…