Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.92 KB

README.md

File metadata and controls

54 lines (40 loc) · 1.92 KB

QR codes on macOS using Swift 5

Example usage. It creates a QR code given text, quality, size, and color parameters. It also demonstrates how to parse and validate the generated QR code as soon as it's generated.

func makeQRCode() {
let text = "https://github.com/atchoo78/QRCodesMacOS"
let backgroundColorStart = .black
// Uncomment for Gradient background:
// let backgroundColorEnd = .gray
let pointColorStart = .red
// Uncomment for Gradient foreground color:
// let pointColorEnd = .purple

let generatedQR = generateQrCode(text: text!, pointColorStart: pointColorStart, pointColorEnd: nil, backgroundColorStart: backgroundColorStart, backgroundColorEnd: nil)

// update UI
<Some ImageView>.image = generatedQR
if(parseQR(QR: generatedQR!.ciImage())[0] != nil) {
	qrURLString = parseQR(QR: generatedQR!.ciImage())[0]
	<Some Textfield>.stringValue = qrURLString!
}


func generateQrCode(text: String, pointColorStart: NSColor, pointColorEnd: NSColor?, backgroundColorStart: NSColor, backgroundColorEnd: NSColor?) -> NSImage? {

   	let correction = QRCode.Quality.high
    	let size: CGFloat = 600
    
    	let pointColor = QRCode.PointColor(<img width="153" alt="qr5" src="https://user-images.githubusercontent.com/20549049/220308914-bed96b3f-b221-44b6-8a9d-67ae8bd34c32.png">

        	start: pointColorStart,
        	end: pointColorEnd
    	)
    
		let backgroundColor = QRCode.BackgroundColor(
        	start: backgroundColorStart,
        	end: backgroundColorEnd
    	)
    
    	return QRGenerator.create(
        	text: text,
		background: backgroundColor,
		color: pointColor,
        	size: size,
        	correction: correction
    	)
}

Generated QR codes

qr3 qr5