Install EFQRCode via CocoaPods
mainAdd EFQRCode to your Podfile to manage it via CocoaPods. Use version ~> 7.0.3.
pod 'EFQRCode', '~> 7.0.3'Then run:
$ pod installrepository·main·Indexed 26 days ago
https://github.com/efprefix/efqrcodeA lightweight, pure-Swift library for generating stylized static and animated QR code images with watermark support, and recognizing QR codes from images. Compatible with iOS, macOS, watchOS, tvOS, and visionOS. Supports various export formats including PNG, JPEG, PDF, GIF, APNG, SVG, and MP4.
Add EFQRCode to your Podfile to manage it via CocoaPods. Use version ~> 7.0.3.
pod 'EFQRCode', '~> 7.0.3'Then run:
$ pod installCartfile and run the update command to build the framework.Add EFQRCode as a dependency in your Package.swift file.
dependencies: [
.package(url: "https://github.com/EFPrefix/EFQRCode.git", .upToNextMinor(from: "7.0.3"))
]Use EFQRCode.Generator to create a stylized QR code. You can pass a URL or string and apply a style using an image as a watermark or icon.
import EFQRCode
let generator = try? EFQRCode.Generator("https://github.com/EFPrefix/EFQRCode", style: .image(
params: .init(image: .init(image: .static(image: .static(image: UIImage(named: "WWF")?.cgImage!)!, allowTransparent: true)))
))
if let image = try? generator?.toImage(width: 180).cgImage {
print("Create QRCode image success \(image)")
} else {
print("Create QRCode image failed!")
}Create dynamic QR codes by passing a sequence of CGImage objects and their corresponding delays to the generator. Use toGIFData(width:) to export the result.
import EFQRCode
let generator = try? EFQRCode.Generator("https://github.com/EFPrefix/EFQRCode", style: .image(
params: .init(image: .init(image: .animated(images: cgImages, imageDelays: cgImageDelays)))
))
if let imageData = try? generator?.toGIFData(width: 512) {
print("Create QRCode image success \(imageData)")
} else {
print("Create QRCode image failed!")
}Use EFQRCode.Recognizer to extract QR code content from a CGImage. The recognize() method returns an array of strings, as a single image may contain multiple QR codes.
import EFQRCode
if let testImage = UIImage(named: "test.png")?.cgImage {
let codes = EFQRCode.Recognizer(image: testImage).recognize()
if !codes.isEmpty {
print("There are \(codes.count) codes")
for (index, code) in codes.enumerated() {
print("The content of QR Code \(index) is \(code).")
}
} else {
print("There is no QR Codes in testImage.")
}
}EFQRCode supports various export types depending on whether the generation is static or animated:
Static Exports:
NSImageUIImagePDFPNGJPEGAnimated Exports:
APNGGIFSVGMOVMP4M4V