UnsplashImageView
UnsplashImageView 允许在 UIImageView 中显示 Unsplash 照片并在图片之间进行过渡。它使用 Unsplash Source API。
要求
- Xcode 9.0+
- iOS 8.0+
安装
UnsplashImageView 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile 中
pod 'UnsplashImageView'
用法
import UnsplashImageView
使用默认配置
UnsplashConfig.default.query = .random(featured: true) // Query to Unsplash. Default is `.random(featured: false)`.
UnsplashConfig.default.size = CGSize(width: 600, height: 600) // Specifies the size of images. Default is `nil`.
UnsplashConfig.default.terms = ["fruit", "vegan"] // Search terms. Default is `nil`.
UnsplashConfig.default.mode = .gallery(interval: 10.0, transition: .fade(0.5)) // Image loading mode. Default is `single`.
UnsplashConfig.default.fixed = .none
开始获取图片
let imageView = UIImageView()
// ...
imageView.unsplash.start()
停止获取图片(如果开启了 gallery
模式)
imageView.unsplash.stop()
使用自定义配置
var config = UnsplashConfig()
config.query = .randomFromUser(username: "ari_spada")
config.mode = .single(transition: .none)
config.fixed = .daily
imageView.unsplash.start(with: config)
模式
single
获取单个图片。gallery
每 x 秒获取一张新的图片。
查询
photo(id: String)
。通过ID获取特定照片。random(featured: Bool)
。从Unsplash获取随机照片。如果featured
为true
,则从精选集合中获取。randomFromUser(username: String)
。从特定用户那里获取随机照片。randomFromUserLikes(username: String)
。从用户的赞中获取随机照片。randomFromCollection(id: String)
。从特定集合中获取随机照片。
更新
none
。始终请求新照片。默认值。daily
。在一天内返回对相同查询相同的照片。weekly
。在一周内返回对相同查询相同的照片。
作者
[email protected],Adrián Bouza Correa
授权
UnsplashImageView遵循MIT授权。更多详情请查看LICENSE文件。