Xode Playground에서 바코드를 생성하는 샘플 코드입니다.

import UIKit
import PlaygroundSupport
import CoreImage

class myViewController : UIViewController {

override func loadView() {
let view = UIView()

let imageView = UIImageView()

let sBarcode = "12345678900987654321"; // 16자리숫자
let dataBarcode = sBarcode.data(using: .ascii)

let ciFilter = CIFilter(name: "CICode128BarcodeGenerator")
ciFilter?.setValue(dataBarcode, forKey: "inputMessage")
let ciImage = ciFilter?.outputImage
let transform = CGAffineTransform(scaleX: 3, y: 2)
let output = ciImage?.applying(transform)
let imgBarcode = UIImage(ciImage: output!)
imageView.image = imgBarcode

imageView.frame = CGRect(x: 0, y: 0, width: 300, height: 100)
view.addSubview(imageView)
self.view = view
}

}

PlaygroundPage.current.liveView = myViewController()
Show your support

Clapping shows how much you appreciated Gzone Lee’s story.