测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2017年2月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Eli Gregory 维护。
ExhibitionSwift 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod "ExhibitionSwift"
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
图像库似乎通常都是基于某种特权构建的。有些是为本地存储的图像设计的,有些是为远程图像设计的。有些强加给您可能不想要的特性 - 例如分享按钮,而其他的则带有不可定制的 UI 元素。有些只维护一组静态图像,而其他的则允许您添加 - 但不能删除!
我在 Exhibition 的目标是为您的设计创建一个简单集成、优雅使用且易于自定义的图像库。
首先使用配置对象设置您的控制器。
let config = ExhibitionConfig()
每个角落都有四个按钮和一个页面控件。按您的喜好进行自定义。
config.swButton.image = UIImage(named: "deleteButton")
config.swButton.imageHighlighted = UIImage(named: "deleteButtonHighlighted")
config.seButton.image = UIImage(named:"addButton")
config.swButton.imageHighlighted = UIImage(named: "addButtonHighlighted")
config.nwButton.hidden = true
config.neButton.title = "Exit"
config.generalTheme.errorImage = UIImage(named: "failedToLoadImage")
config.generalTheme.backgroundColor = .black
config.generalTheme.foregroundColor = .white
config.buttonsTheme.buttonsTitleColor = .red
config.buttonsTheme.buttonsTitleColorHighlighted = .orange
您可以通过订阅 ExhibitionDownloaderProtocol
来编写您自己的 Image Networking 类,或者使用内置的 ExhibitionDownloader
。
public protocol ExhibitionDownloaderProtocol {
func downloadImage(image: ExhibitionImageProtocol, results: @escaping ((UIImage?, Error?)->()))
}
您可以通过订阅 ExhibitionCacheProtocol
来编写您自己的 Image Cache 或将其集成到现有的缓存中,或者使用内置的 ExhibitionCache
。
public protocol ExhibitionCacheProtocol {
func set(image img:UIImage, forKey key: String)
func retrieveImage(forKey key: String) -> UIImage?
}
您可以直接将 ExhibitionImageProtocol
集成到您的模型中,或者使用内置的 ExhibitionImage
结构。
public protocol ExhibitionImageProtocol {
var image: UIImage? { get }
var url: URL? { get }
var shouldCache: Bool { get }
}
// OR
var imgs: [ExhibitionImageProtocol] = [
ExhibitionImage(string: "https://upload.wikimedia.org/wikipedia/commons/b/b8/ESO_Very_Large_Telescope.jpg")!,
ExhibitionImage(string: "https://upload.wikimedia.org/wikipedia/commons/f/f0/Moonset_over_ESO's_Very_Large_Telescope.jpg")!,
ExhibitionImage(string: "https://upload.wikimedia.org/wikipedia/commons/e/e0/Large_Scaled_Forest_Lizard.jpg")!,
ExhibitionImage(string: "http://bsnscb.com/data/out/113/39939274-large-wallpapers.jpeg")!,
ExhibitionImage(string: "http://kingofwallpapers.com/lava/lava-003.jpg")!,
ExhibitionImage(string: "https://www.woolme.com/blog/wp-content/uploads/2016/03/requests-alpaca_2441680k.jpg")!
]
/*
Optionally:
ExhibitionImage(url: URL)
ExhibitionImage(image: UIImage)
*/
最后,构建一个 ExhibitionController
。
let controller = ExhibitionController(with: requiredImages,
config: optionalConfig,
cache: optionalCache,
downloader: optionalDownloader
为您的按钮设置一些操作。
controller.neClosure = { button, controller in
controller.dismiss(animated: true, completion: nil)
}
controller.swClosure = { button, controller in
controller.disableControllerInteractions()
let newImageURL = URL(string: "https://www.national-park.com/wp-content/uploads/2016/04/Welcome-to-Death-Valley-National-Park.jpg")!
let img = ExhibitionImage(url: newImageURL)
controller.append(exhibitionImage: img, scrollToLast: true)
controller.enableControllerInteractions()
}
closure.seClosure = { button, controller in
controller.disableControllerInteractions()
_ = controller.removeCurrentExhibitionImage()
controller.enableControllerInteractions()
}
您甚至可以设计自己的自定义UIView子类活动指示器,如果您订阅了通过覆盖newActivityView
闭包的ExhibitionActivityIndicatorViewProtocol
。
public var newActivityView: ActivityViewGenerator = { controller, sized in
//...
// return <ExhibititionActivityIndicatorViewProtocol>
}
public typealias ActivityViewGenerator = (_ controller: ExhibitionController, _ sized: CGSize) -> (ExhibititionActivityIndicatorViewProtocol)
展览目前处于测试版,未来几个月将继续开发。它尚未在行业标准下进行测试,请自行承担风险。
Eli Gregory, [email protected]
ExhibitionSwift受MIT许可证的约束。有关更多信息,请参阅LICENSE文件。