Skip to content

Instantly share code, notes, and snippets.

@ghecho
Last active May 29, 2019 12:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghecho/d79bd02213e608053ec12a8e616f1dbf to your computer and use it in GitHub Desktop.
Save ghecho/d79bd02213e608053ec12a8e616f1dbf to your computer and use it in GitHub Desktop.
Generate a QR image from a string using Swift 4
import CoreImage
static func createQR(fromString: String) -> CIImage?
{
let stringData = fromString.data(using: .utf8)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter?.setValue(stringData, forKey: "inputMessage")
filter?.setValue("H", forKey: "inputCorrectionLevel")
let qrCodeImage = filter?.outputImage
let imageByTransform = qrCodeImage?.transformed(by: CGAffineTransform(scaleX: 15.0, y: 15.0))
return imageByTransform
}
@Neelu1112
Copy link

How to create colored QRCode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment