测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可 | MIT |
发布最后发布 | 2017年12月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✓ |
由 Pablo Camiletti 维护。
此项目的背后理念是创建一个易于使用、经过良好测试和良好记录的 Unsplash 客户端框架。
目前处于早期开发阶段
🍼
将以下内容添加到您的 Podfile
:
pod 'UnsplashFramework', '~> 0.1'
将以下内容添加到您的 Cartfile
:
github "camiletti/UnsplashFramework" ~> 0.1
import UnsplashFramework
在进行任何请求之前,应设置 Unsplash 客户端凭证。如果您尚未注册,可以在此注册:这里。
UNClient.shared.setAppID("Your_AppID", secret: "Your_Secret")
UNClient.shared.listPhotos(page: 1, photosPerPage: 10, sortingBy: .popular) { (photos, error) in
if let error = error {
print("Error: \(error.reason)")
return
}
photos.forEach({ (photo) in
print("Photo with ID: \(photo.id) from user: \(photo.user.username) main color: \(photo.hexColor)")
})
}
为了更好地性能和网络利用,UNPhoto 保留了照片的所有信息(除了图像)。照片的图像可以独立请求,有 5 种大小(原始、完整、常规、小型和缩略图)。使用以下 UIImageView 函数将处理网络请求,并在下载完成后设置图像。可以设置照片的主要颜色作为请求过程中的背景。
let imageView = UIImageView()
imageView.backgroundColor = photo.color
imageView.setImage(from: photo, inSize: .small)
let imageView = UIImageView()
self.client.fetchImage(from: samplePhoto,
inSize: .full) { (requestedPhoto, requestedSize, image, error) in
if let error = error {
print("Error: \(error.reason)")
return
}
imageView.image = image
}
UnsplashFramework 使用 MIT 许可。
Copyright 2017 Pablo Camiletti
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.