QRCodeGenerate is a QRCode generater to generate qrCode as image in iOS + iPadOS , and NSImage in MacOS, with full freedom of passing any codable object , and changing backgroundColor , QRCode color.
.package(url: "https://github.com/TariqAlmazyad/QRCodeGenerate.git")
import SwiftUI
import QRCodeGenerate
struct PhoneView: View {
@State private (set) var user = User(email: "sample@gmail.com", name: "username")
var body: some View {
#if os(iOS) || os(watchOS) || os(tvOS)
LazyVGrid(columns: [
GridItem(.adaptive(minimum: 200, maximum: 240))
], alignment: .center, content: {
Image(uiImage: .generateQRCode(from: user, backgroundColor: .white,
QRCodeColor: CIColor(color: UIColor(Color(#colorLiteral(red: 0.9098039269, green: 0.4784313738, blue: 0.6431372762, alpha: 1))))))
.resizable()
.interpolation(.none)
.scaledToFill()
.frame(width: 200, height: 200)
Image(uiImage: .generateQRCode(from: user, backgroundColor: .white,
QRCodeColor: CIColor(color: UIColor(Color(#colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, alpha: 1))))))
.resizable()
.interpolation(.none)
.scaledToFill()
.frame(width: 200, height: 200)
Image(uiImage: .generateQRCode(from: user, backgroundColor: .white,
QRCodeColor: CIColor(color: UIColor(Color(#colorLiteral(red: 0.1411764706, green: 0.0431372549, blue: 0.2117647059, alpha: 1))))))
.resizable()
.interpolation(.none)
.scaledToFill()
.frame(width: 200, height: 200)
Image(uiImage: .generateQRCode(from: user, backgroundColor: .white,
QRCodeColor: CIColor(color: UIColor(Color(#colorLiteral(red: 0.2745098174, green: 0.4862745106, blue: 0.1411764771, alpha: 1))))))
.resizable()
.interpolation(.none)
.scaledToFill()
.frame(width: 200, height: 200)
})
#endif
}
}
There are some extra steps for MacOS . Here is the steps below:
and then you can import the library
import QRCodeGenerate
struct MacOSView: View {
@State private (set) var user = User(email: "sample@gmail.com", name: "username")
var body: some View {
#if os(macOS)
LazyVGrid(columns: [
GridItem(.adaptive(minimum: 500, maximum: 640))
], alignment: .center, content: {
Image(nsImage: .generateQRCode(from: user, backgroundColor: .white,
QRCodeColor: CIColor(cgColor: #colorLiteral(red: 0.9098039269, green: 0.4784313738, blue: 0.6431372762, alpha: 1))))
.resizable()
.interpolation(.none)
.scaledToFill()
.frame(width: 400, height: 400)
Image(nsImage: .generateQRCode(from: user, backgroundColor: .white,
QRCodeColor: CIColor(cgColor: #colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, alpha: 1))))
.resizable()
.interpolation(.none)
.scaledToFill()
.frame(width: 400, height: 400)
Image(nsImage: .generateQRCode(from: user, backgroundColor: .white,
QRCodeColor: CIColor(cgColor: #colorLiteral(red: 0.1411764706, green: 0.0431372549, blue: 0.2117647059, alpha: 1))))
.resizable()
.interpolation(.none)
.scaledToFill()
.frame(width: 400, height: 400)
Image(nsImage: .generateQRCode(from: user, backgroundColor: .white,
QRCodeColor: CIColor(cgColor: #colorLiteral(red: 0.2745098174, green: 0.4862745106, blue: 0.1411764771, alpha: 1))))
.resizable()
.interpolation(.none)
.scaledToFill()
.frame(width: 400, height: 400)
})
#endif
}
}
import SwiftUI
import QRCodeGenerate
struct PhoneView: View {
@State private (set) var user = User(email: "sample@gmail.com",
name: "username")
var body: some View {
LazyVGrid(columns: [
GridItem(.adaptive(minimum: 200, maximum: 240))
], alignment: .center, content: {
generateQRCode(from: user, backgroundColor: .black, QRCodeColor: .white,
qrCodeSize: 200,logo: Image("logo"), logoSize: 60)
generateQRCode(from: user, backgroundColor: .black, QRCodeColor: .cyan,
qrCodeSize: 200 ,logo: Image("linkedin"), logoSize: 60)
generateQRCode(from: user, backgroundColor: .black, QRCodeColor: .gray,
qrCodeSize: 200 ,logo: Image("twitter"), logoSize: 60)
generateQRCode(from: user, backgroundColor: .black, QRCodeColor: .white,
qrCodeSize: 200 ,logo: Image("xcode"), logoSize: 60)
})
}
}