zcscan 是一个基于 Swift 的二维码扫描组件,支持自定义 UI 和相册选择,集成简单,扩展性强。
pod 'zcscan'
你可以通过 SPM 集成,在 Xcode 的菜单栏选择 File > Add Packages...
,输入:
https://github.com/你的GitHub用户名/zcscan.git
或在 Package.swift
里添加依赖:
.package(url: "https://github.com/你的GitHub用户名/zcscan.git", from: "1.0.0")
在 Podfile 添加后,执行 pod install
。
在你的 ViewController 中导入:
import zcscan
let vc = ZCScanViewController.present(fromVC: self, albumClickBlock: nil, resultBlock: { link in
// 返回的是选择的二维码信息,这里处理自己的业务逻辑
print("link===>>\(link)")
})
vc = ZCScanViewController.push(fromVC: self, albumClickBlock: { seletPhoto in
ZLPhotoConfiguration.default().maxSelectCount = 1
ZLPhotoConfiguration.default().allowEditImage = false
ZLPhotoConfiguration.default().allowSelectVideo = false
ZLPhotoConfiguration.default().allowTakePhotoInLibrary = false
let picker = ZLPhotoPicker()
picker.selectImageBlock = { results, isOriginal in
if let img = results.first?.image {
seletPhoto(img)
}
}
picker.cancelBlock = {
// 取消回调
}
if let vc {
picker.showPhotoLibrary(sender: vc)
}
}, resultBlock: { link in
print("link===>>\(link)")
})
zcscan 支持高度自定义 UI,所有属性均为公开属性,可灵活调整。例如:
let config = ZCScanManager.shared.conifg
config.selectQrcodeBtnImage = UIImage(named: "qrcode_arrow")
config.scanninglineImage = UIImage(named: "scan_line")
// 更多配置项请参考 ScanConfig.swift
@IBAction func openScan(_ sender: Any) {
let config = ZCScanManager.shared.conifg
config.selectQrcodeBtnImage = UIImage(named: "qrcode_arrow")
config.scanninglineImage = UIImage(named: "scan_line")
let vc = ZCScanViewController.present(fromVC: self, albumClickBlock: nil, resultBlock: { link in
// 返回二维码内容
print("link===>>\(link)")
})
}
更多用法请参考 Example 工程中的 ViewController.swift。
ZClee, [email protected]
zcscan is available under the MIT license. See the LICENSE file for more info.