LTImagePicker
示例
示例项目包含了一个关于如何使用该pod的示例。您可以自由地操作它。要运行示例项目,请先克隆仓库,然后在示例文件夹中运行 pod install
。
使用方法
-
创建协调器
在您想要流程开始的 ViewController 中创建一个 LTImagePickerCoordinator
,传递一个 LTPickerConfig
来自定义外观。添加一个 Notification
来接收您最终选择的图片。
var coordinator: LTImagePickerCoordinator?
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(selectedImage(_:)), name: .didFinishPickingImage, object: nil)
let config = LTPickerConfig(navBackgroundColor: UIColor.black,
navTintColor: UIColor.white,
accentColor: UIColor(red: 249/255, green: 215/255, blue: 68/255, alpha: 1),
shouldShowTextInput: false)
coordinator = LTImagePickerCoordinator(configuration: config)
}
-
开始流程
然后只需调用
coordinator?.startCameraFlow(from: self)
使用相机开始流程。否则调用
coordinator?.startLibraryPickerFlow(from: self)
使用相册开始流程。
-
获取图片和消息
调用在 Notification
中通过选择器传入的函数,以接收可用的数据。
@objc private func selectedImage(_ sender: Notification) {
// Image always exists
if let image = sender.userInfo?["image"] as? UIImage {
}
// Message is available only if you decided to show the textInput
// in the LTPickerConfig and you write something
if let message = sender.userInfo?["message"] as? String, !message.isEmpty {
}
}
安装
LTImagePicker 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod 'LTImagePicker'
并运行 pod install
作者
LorTos, [email protected]
许可协议
LTImagePicker 适用于 MIT 许可协议。有关更多信息,请参阅 LICENSE 文件。