SwiftUPC
一个轻量级库,可以用于从文本数据生成 UPC-A 条形码。目前提供从字符串表示形式解析结构化条形码数据的功能,以及用于显示条形码数据的自定义 UIKit 视图。
示例
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
要求
SwiftUPC 除了 UIKit 外,没有其他外部依赖。
安装
SwiftUPC 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'SwiftUPC'
使用
import SwiftUPC
解析原始字符串数据
如果您有一个UPC-A条形码号并以String格式存储,可以使用UPCABarcodeGenerator.upcaBarcodeModules(from string: String)
将其解析成结构化的条形码数据。
let barcodeString = "474003059110"
// The below call can throw if parsing fails. See `BarcodeGeneratorError` for more info.
let barcodeModules = try! UPCABarcodeGenerator.upcaBarcodeModules(from: barcodeString)
显示条形码
使用自定义视图UPCABarcodeView
在您的界面中显示条形码。UPCABarcodeView
将使用提供的条形码填充其边界。
let barcodeView: UPCABarcodeView // initialized somewhere in code, Storyboard, or Xib
barcodeView.barcodeModules = barcodeModules
作者
许可
SwiftUPC采用MIT许可。有关更多信息,请参阅LICENSE文件。