测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可协议 | MIT |
发布最新发布 | 2017年1月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由Michael Skiba,Raiz Labs,Alex Rouse,Rightpoint CI维护。
iOS 图像库
RIGImageGallery 是一个旨在提供系统照片应用中图像库大部分功能的照片库,并处理图像的异步加载。
此库是 Raizlabs 接口指南的一部分,这些是 UI 组件,提供合理的默认值,以帮助项目快速启动,使用起来感觉像本地组件,并且具有易于使用的自定义选项。
.swift
文件,并将其放入您的项目中。要查看使用库的完整示例,请查看 示例项目。
func createPhotoGallery() -> RIGImageGalleryViewController {
let urls: [URL] = [
"https://placehold.it/1920x1080",
"https://placehold.it/1080x1920",
"https://placehold.it/350x150",
"https://placehold.it/150x350",
].flatMap(URL.init(string:))
let rigItems: [RIGImageGalleryItem] = urls.map { _ in
RIGImageGalleryItem(placeholderImage: UIImage(named: "placeholder") ?? UIImage(),
isLoading: true)
}
let rigController = RIGImageGalleryViewController(images: rigItems)
for (index, URL) in urls.enumerated() {
let request = imageSession.dataTask(with: URLRequest(url: URL)) { [weak rigController] data, _, error in
if let image = data.flatMap(UIImage.init), error == nil {
rigController?.images[index].image = image
rigController?.images[index].isLoading = false
}
}
request.resume()
}
return rigController
}
@objc func showGallery(_ sender: UIButton) {
let photoViewController = createPhotoGallery()
photoViewController.dismissHandler = dismissPhotoViewer
photoViewController.actionButtonHandler = actionButtonHandler
photoViewController.actionButton = UIBarButtonItem(barButtonSystemItem: .action, target: nil, action: nil)
photoViewController.traitCollectionChangeHandler = traitCollectionChangeHandler
photoViewController.countUpdateHandler = updateCount
let navigationController = UINavigationController(rootViewController: photoViewController)
present(navigationController, animated: true, completion: nil)
}
func dismissPhotoViewer(_ :RIGImageGalleryViewController) {
dismiss(animated: true, completion: nil)
}
func actionButtonHandler(_: RIGImageGalleryViewController, galleryItem: RIGImageGalleryItem) {
}
func updateCount(_ gallery: RIGImageGalleryViewController, position: Int, total: Int) {
gallery.countLabel.text = "\(position + 1) of \(total)"
}
func traitCollectionChangeHandler(_ photoView: RIGImageGalleryViewController) {
let isPhone = UITraitCollection(userInterfaceIdiom: .phone)
let isCompact = UITraitCollection(verticalSizeClass: .compact)
let allTraits = UITraitCollection(traitsFrom: [isPhone, isCompact])
photoView.doneButton = photoView.traitCollection.containsTraits(in: allTraits) ? nil : UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
}
欢迎提交问题和拉请求!请确保您已安装最新版本的 SwiftLint,提交前请确保构建时没有生成任何风格警告。
期望贡献者遵守 贡献者守则。
RIGImageGallery 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。
Michael Skiba, [email protected] @atelierclkwrk