Unsplash Photo Picker for iOS
UnsplashPhotoPicker 是一个 iOS UI 组件,它允许您通过几行代码快速搜索 Unsplash 库中的免费高质量照片。
Android 照片选择器 在此。
目录
描述
UnsplashPhotoPicker 是一个视图控制器。您将其显示给用户以选择一张或多张来自 Unsplash 的照片。一旦他们选择了照片,视图控制器将返回您可以在应用程序中使用 UnsplashPhoto
对象。
要求
- iOS 12.1+
- Xcode 12.5+
- Swift 5.3+
- Unsplash API 访问密钥和密钥
安装
Swift 包管理器
要使用 Swift 包管理器 将 UnsplashPhotoPicker 集成到您的 Xcode 项目中,请通过 文件 > Swift 包 > 添加包依赖...
打开依赖关系管理器。
并插入仓库 URL
https://github.com/unsplash/unsplash-photopicker-ios.git
要在您自己的包中添加依赖项,只需在 Package.swift
的依赖项中指定它。
.package(
name: "UnsplashPhotoPicker",
url: "https://github.com/unsplash/unsplash-photopicker-ios.git",
.upToNextMajor(from: "1.3.0")
)
Carthage
要使用 Carthage 将 UnsplashPhotoPicker 集成到 Xcode 项目中,请在其 Cartfile
中指定它。
github "unsplash/unsplash-photopicker-ios" ~> 1.3
运行 carthage update
构建框架,然后将构建好的 UnsplashPhotoPicker.framework
拖入您的 Xcode 项目中。
CocoaPods
要使用 CocoaPods 将 UnsplashPhotoPicker 集成到 Xcode 项目中,请在其 Podfile
中指定它。
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.1'
use_frameworks!
target '<Your Target Name>' do
pod 'UnsplashPhotoPicker', '~> 1.3'
end
然后运行 pod install
。
Git 子模块
如果您不想使用上述任一依赖关系管理器,您可以手动作为 git 子模块 将 UnsplashPhotoPicker 集成到项目中,在项目文件夹中运行以下命令
$ git submodule add https://github.com/unsplash/unsplash-photopicker-ios.git
将 UnsplashPhotoPicker.xcodeproj
文件拖入您的 Xcode 项目中,然后将其拖到目标 “嵌入式二进制文件” 中 UnsplashPhotoPicker.framework
。
使用方法
配置
UnsplashPhotoPicker
通过UnsplashPhotoPickerConfiguration
的实例进行配置
UnsplashPhotoPickerConfiguration(accessKey: String,
secretKey: String,
query: String,
allowsMultipleSelection: Bool,
memoryCapacity: Int,
diskCapacity: Int)
属性 | 类型 | 可选/必需 | 默认值 |
---|---|---|---|
accessKey |
字符串 | 必需 | 不适用 |
secretKey |
字符串 | 必需 | 不适用 |
query |
字符串 | 可选 | nil |
allowsMultipleSelection |
布尔值 | 可选 | false |
memoryCapacity |
整型 | 可选 | 50 |
diskCapacity |
整型 | 可选 | 100 |
contentFilterLevel |
内容过滤级别 | 可选 | .low |
展示
UnsplashPhotoPicker
是UINavigationController
的子类。我们建议在iPad上以模态或弹窗方式展示它。在展示之前,您需要实现UnsplashPhotoPickerDelegate
协议,并使用photoPickerDelegate
属性获取结果。
protocol UnsplashPhotoPickerDelegate: class {
func unsplashPhotoPicker(_ photoPicker: UnsplashPhotoPicker, didSelectPhotos photos: [UnsplashPhoto])
func unsplashPhotoPickerDidCancel(_ photoPicker: UnsplashPhotoPicker)
}
使用结果
UnsplashPhotoPicker
返回一个包含UnsplashPhoto
对象的数组。更多详细信息,请参阅UnsplashPhoto.swift。
软件许可协议
MIT许可证
版权所有 © 2018-2022 Unsplash Inc。
本文件授权任何人复制此软件及其相关文档文件(“软件”),不受限制地处理此软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许软件的受让人执行上述行为,但必须符合以下条件:
上述版权声明和本许可声明应包含在软件的所有副本或实质性部分中。
软件按“原样”提供,不提供任何形式的保证,无论是明示的、默示的还是其他的,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或任何其他原因,无论这些索赔、损害或其他责任是从、因或与软件或其使用或其他方式而产生的。