ADPhotoKit 是一个纯 Swift 库,用于从系统相册中选择资产(例如照片、视频、GIF、Livephoto)。默认外观类似于微信。
特性
- 良好的文档。
- 支持单选和复选。
- 支持过滤相册并按类型排序。
- 支持 iCloud。
- 多语言。
- 高度可定制,基于 协议(UI/图像/颜色/字体)。
- 支持 UIAppearance。
- 支持批量导出 PHAsset 到图像。
- 图像编辑器。
- 支持 DocC。
- 支持自定义相机。
- 支持视频编辑器。
用法
快速入门
最简单的用法是在您的控制器中显示图库选择器
ADPhotoKitUI.imagePicker(present: self) { (assets, origin) in
// do something
}
更高级的示例
选择最多 9 张图片或视频
ADPhotoKitUI.imagePicker(present: self,
params: [.maxCount(max: 9)],
selected: { (assets, origin) in
// do something
})
选择 1 个视频或 9 张图片
ADPhotoKitUI.imagePicker(present: self,
assetOpts: .exclusive,
params: [.maxCount(max: 9),.imageCount(min: nil, max: 9),.videoCount(min: nil, max: 1)],
selected: { (assets, origin) in
// do something
})
选择最多 8 张图片
ADPhotoKitUI.imagePicker(present: self,
albumOpts: [.allowImage],
assetOpts: .exclusive,
params: [.maxCount(max: 8)],
selected: { (assets, origin) in
// do something
})
浏览网络图片和视频
ADPhotoKitUI.assetBrowser(present: self,
assets: [NetImage(url: "https://example.com/xx.png"), NetVideo(url: "https://example.com/xx.mp4")]) { assets in
// do something
}
有关更多用法配置,您可以查看 ADPhotoKitUI。
了解更多
要了解更多关于 ADPhotoKit 的用法,请参考示例和 API 参考。
要求
- iOS 10.0
- Swift 5.0+
不支持 Objective-C。Swift 是未来,放弃 Obj-C 是为了保持本库的速度而付出的代价 :)
安装
CocoaPods
ADPhotoKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile:
source 'https://cdn.cocoapods.org/'
platform :ios, '10.0'
use_frameworks!
target 'MyApp' do
pod 'ADPhotoKit'
end
需要 cocoaPods 1.12.0+ 才能支持 DocC
子模块
现在有 4 个可用的子模块
子模块 | 描述 |
---|---|
Base | 必需。此子模块提供基本的配置和扩展。 |
Core | 可选。此子模块提供原始数据。 |
CoreUI | 可选。此子模块提供照片选择的 UI。 |
ImageEdit | 可选。此子模块提供图像编辑能力。 |
您可以根据需要安装 ADPhotoKit 的某些模块。默认情况下,您会获得 CoreUI
子模块。
Swift 包管理器
- 文件 > Swift 包 > 添加包依赖
- 添加 https://github.com/duzexu/ADPhotoKit.git
- 选择 "分支" 为 "master"
注意
您需要在应用程序的 Info.plist 中添加以下键值对
// If you don’t add this key-value pair, multiple languages are not supported, and the system PhotoKitUI language defaults to English
Localized resources can be mixed YES
// You must add follow in your app's Info.plist
Privacy - Photo Library Usage Description
// If you `assetOpts` contain `allowTakePhotoAsset`, you must add follow
Privacy - Camera Usage Description
// If you `assetOpts` contain `allowTakeVideoAsset`, you must add follow
Privacy - Microphone Usage Description
贡献
如果您有功能请求或错误报告,请随时通过发送拉取请求或创建新问题来帮助。
许可
ADPhotoKit 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。
一些代码和资源是从 ZLPhotoBrowser 拷贝的