Pickle
Carousell图片选择器。
- 跨专辑进行多图选择
- 按照所需顺序选择照片
- 可自定义主题
使用方法
import Pickle
使用方法与UIImagePickerController
类似
let picker = ImagePickerController()
picker.delegate = self as? ImagePickerControllerDelegate
present(picker, animated: true, completion: nil)
显示预选图片
let assets: [PHAsset] = []
let picker = ImagePickerController(selectedAssets: assets)
ImagePickerController
在显示时会请求访问相册的权限(如果需要)。
委托
ImagePickerControllerDelegate
负责关闭图片选择器。所需委托方法
/// Asks the delegate if the image picker should launch camera with certain permission status.
func imagePickerController(_ picker: ImagePickerController, shouldLaunchCameraWithAuthorization status: AVAuthorizationStatus) -> Bool
/// Tells the delegate that picker has finished launching camera with an array of selected assets
@objc optional func imagePickerController(_ picker: ImagePickerController, didFinishLaunchingCameraWith assets: [PHAsset])
/// Tells the delegate that the user picked image assets. The delegate is responsible for dismissing the image picker.
func imagePickerController(_ picker: ImagePickerController, didFinishPickingImageAssets assets: [PHAsset])
/// Tells the delegate that the user cancelled the pick operation. The delegate is responsible for dismissing the image picker.
func imagePickerControllerDidCancel(_ picker: ImagePickerController)
外观
使用修改后的Parameters
结构或任何遵循ImagePickerConfigurable
的类型的结构来自定义外观。
var parameters = Pickle.Parameters()
parameters.allowedSelections = .limit(to: 4)
let picker = ImagePickerController(configuration: parameters)
查看ImagePickerConfigurable.swift以获取完整的可配置属性列表。
相机
UIImagePickerController
用sourceType = .camera
作为设备上的默认相机。通过提供CameraCompatible
类型或闭包来返回已配置的相机控制器实例,从相册启动自定义相机。
let picker = ImagePickerController(
selectedAssets: [],
configuration: Pickle.Parameters(),
cameraType: UIImagePickerController.self
)
let initializer = {
return UIImagePickerController()
}
let picker = ImagePickerController(
selectedAssets: [],
configuration: Pickle.Parameters(),
camera: initializer
)
此功能将更新selectedAssets
属性的新值并更新UI。不会触发任何delegate
回调
public func updateSelectedAssets(with assets: [PHAsset]) { }
文档
Pickle参考
https://carousell.github.io/pickle
配置示例
gem install cocoapods
设置开发pods
make bootstrap
要求
Pickle | iOS | Xcode | Swift |
---|---|---|---|
>= 1.0.0 |
8.0+ | 8.3.3 | |
>= 1.2.0 |
9.0+ | 8.3.3 | |
>= 1.3.0 |
9.0+ | 9.2 |
安装
CocoaPods
使用创建以下规范的 Podfile
并运行 pod install
。
platform :ios, '9.0'
use_frameworks!
pod 'Pickle'
Carthage
使用创建以下规范的 Cartfile
并运行 carthage bootstrap
。按照 说明 将框架添加到项目中。
github "carousell/pickle"
贡献
感谢您对参与此项目感兴趣。有关更多信息,请查看 CONTRIBUTING 文档。
关于
Pickle 由 Carousell 创建和维护。帮助我们改进此项目!我们非常希望听到您的 反馈。
我们在招聘!了解更多信息,请访问 http://careers.carousell.com/
许可
Pickle 遵循 Apache License 2.0 许可。有关详细信息,请参阅 LICENSE。