YCBarcodeReader
安装
对于YCBarcodeReader,在Podfile中使用以下条目
pod 'YCBarcodeReader'
然后运行pod install
。
在任何想要使用YCBarcodeReader的文件中,别忘了使用import YCBarcodeReader导入框架。
用法
无代码Storyboard实现
-
在interface builder中创建一个UIView,并分配自定义类YCBarcodeReaderView。
- 从Storyboard设置YCBarcodeReaderView。
在Storyboard中设置
-
显示/隐藏手电筒按钮;
-
设置手电筒按钮位置
位置 参数 左下角 bottomLeft 右下角 bottomRight 左上角 topLeft 右上角 topRight -
设置边距;
-
更改火炬按钮图像以用于开/关模式;
-
设置开/关的全景方向;
-
显示/隐藏焦点视图;
-
更改焦点视图的边框颜色;
-
更改焦点视图的边框线宽;
-
设置焦点视图的大小。
- 然后在视图控制器中连接代理。
import UIKit
import YCBarcodeReader
class ViewController: UIViewController {
@IBOutlet weak var barcodeReader: YCBarcodeReaderView!
override func viewDidLoad() {
super.viewDidLoad()
barcodeReader.delegate = self
}
}
extension ViewController: YCBarcodeReaderDelegate {
func reader(didReadCode code: String, type: String) {
print(code)
}
func reader(didReceiveError error: Error) {
print(error)
}
}
- 编程设置。
import UIKit
import YCBarcodeReader
class ViewController: UIViewController {
@IBOutlet weak var barcodeReader: YCBarcodeReaderView!
override func viewDidLoad() {
super.viewDidLoad()
barcodeReader.delegate = self
barcodeReader.showTorchButton = true
barcodeReader.torchButtonPosition = .topLeft
barcodeReader.torchButtonInsets = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
barcodeReader.landscapeOrientation = true
barcodeReader.focusViewShowed = true
barcodeReader.focusViewBorderColor = .yellow
barcodeReader.focusViewLineWidth = 5
barcodeReader.focusViewSize = CGSize(width: 250, height: 180)
}
}
作者
YuraChudnick, [email protected]
许可证
YCBarcodeReader许可协议为MIT。更多信息请参阅LICENSE文件。