ios - 如何在 Swift 4 中设置 QRCode 版本

标签 ios swift core-graphics swift4 qr-code

使用 Core Graphic 库,我能够生成几乎任何类型的 .然而,QR-Code,我无法控制 Swift 使用的版本。

根据http://www.qrcode.com/en/about/version.html有好几个版本,分别是

当前代码:

let filter = CIFilter(name: "CIQRCodeGenerator")
filter?.setValue(vcard, forKey: "inputMessage")
filter?.setValue("M", forKey: "inputCorrectionLevel")

if let output = filter?.outputImage {
  let scaleX = qrCode.frame.size.width / output.extent.size.width
  let scaleY = qrCode.frame.size.height / output.extent.size.height
  let transform = CGAffineTransform(scaleX: scaleX, y: scaleY)
  let scaledOutput = output.transformed(by: transform)
  self.qrCode.image = UIImage(ciImage: scaledOutput)
}

不允许我控制正在使用的二维码的版本。它只是确保生成的图像不模糊,就是这样。

对于校正级别,有没有办法将二维码版本传递到 Core Image lib?

最佳答案

根据 documentation

Generates an output image representing the input data according to the ISO/IEC 18004:2006 standard.

我认为是版本 2。版本 3 是 ISO/IEC 18004:2015 标准。根据文档,无法更改 QR 版本。

关于ios - 如何在 Swift 4 中设置 QRCode 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49847729/

相关文章:

iphone - 为 UIImageView 的 CABasicAnimation 强制顺时针/逆时针旋转

ios - 自定义委托(delegate)和数据源 NSObject 最佳实践

ios - 在 Swift 中,可以使用 NSDateComponents 来帮助 NSDate 保持纳秒精度吗?

ios - 在 iOS 应用程序中呈现演练

ios - 使用 swift 设置 UiStackview 内 UiLabel 的高度

ios - 关于转义 URL 参数中的特殊字符的困惑

ios - 设置UIBezierPath的lineWidth不起作用

ios - 将 CIFilter 应用于 UIImage 会导致调整大小和重新定位图像

ios - 如何持久存储 NSManagedObjectID?

ios - Core Graphics 的内存问题