QRect
adds SwiftUI/AppKit/UIKit syntax sugar to the QR code generator built into CoreImage
.
Example Usage
Preview in the included Example.playground
:
import PlaygroundSupport
import SwiftUI
import QRect
var qrCode: QRCode = QRCode(url: URL(string: "https://example.com")!)! // https://example.com
qrCode = QRCode(wifi: "Abraham Linksys", password: "P@$$w0rd", networkType: .wpa)! // WIFI:S:Abraham Linksys;T:WPA;P:P@$$w0rd;;
qrCode = QRCode("https://example.com")! // https://example.com
PlaygroundPage.current.setLiveView(Image(qrCode: qrCode, color: .primary, scale: 3)
.padding())
Also works in both AppKit and UIKit:
import Cocoa
let image: NSImage = NSImage(qrCode: qrCode, color: .textColor, scale: 3)
PlaygroundPage.current.setLiveView(NSImageView(image: image))
import UIKit
let image: UIImage = UIImage(qrCode: qrCode, color: .label, scale: 3)
PlaygroundPage.current.setLiveView(UIImageView(image: image))
Command-Line Interface
Package includes qrect-cli
for saving a QR code of any ASCII string to the working directory as
transparent PNG:
./qrect-cli "https://example.com" -fos 3
By default, the resulting QR code PNG will use the minimum number of pixels needed to encode the ASCII value -- always square and at least 23 pixels. Use --scale
with an integer value greater than 1 to generate larger resolution PNGs:
Requirements
Targets iOS/iPadOS/tvOS 15 and macOS 12 Monterey. Written in Swift 5.5 and builds in Xcode 13 or newer.