QRCode
QRCode copied to clipboard
Logo on the middle ?
Hello,
This a very nice work, but I have one question, it is possible to put a logo in the middle of the QR Code ?
Thank's in advance.
I have the same question about add logo in qrcode.
It is possible by using UIGraphicsImageContext
private func generateQRCode(str: String) -> UIImage? {
guard var qrCode = QRCode(str) else {
return nil
}
qrCode.errorCorrection = .High
guard let qrImage = qrCode.image, let logoImage = UIImage(named: "logo") else {
return nil
}
let logoWidth = qrImage.size.width / 4
UIGraphicsBeginImageContextWithOptions(qrImage.size, false, 0)
qrImage.draw(in: CGRect(origin: .zero, size: qrImage.size))
logoImage.draw(in: CGRect(x: (qrImage.size.width - logoWidth) / 2, y: (qrImage.size.width - logoWidth) / 2,
width: logoWidth, height: logoWidth))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
I don't know this is the best way.
I want function to put image like QRCode#put(image: UIImage)
.