ContentLoader
目录
描述
使用 ContentLoader
在您的内容上展示出色的动画样式加载占位符。使用您自定义的视图创建低对比度的块,具有相同的形状和位置。使用您自定义的格式制作像 Slack、Instagram 或 Facebook 这样的美妙的动画。ContentLoader 使用 Swift 5 编写,适用于 iOS,自定义化和使用简单。
- 加载时的出色动画
- 完全可自定义的
- 也可以在您的自定义表格和集合视图中使用
- 易于使用
- 支持 iOS,使用 Swift 5 开发
示例
要运行示例项目,请先克隆仓库,然后从 Example 目录运行 pod install
。
安装
ContentLoader可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中,并运行pod install
pod 'ContentLoader'
然后您就可以在需要时导入它了
import ContentLoader
使用
在示例中您将看到一些可用于项目的自定义内容加载器。安装pod后,按照以下步骤操作。这非常简单
内容加载器在视图中
选择您的一个自定义ViewController。在您希望使其变为Loadable
的视图控件中,将isLoadable
视图属性设置为true
。当ContentLoader加载时,这些视图将转换为可加载对象。如果您使用xibs / storyboards,您可以看到新的可编辑Is Loadable
属性。
使用表或者集合视图?
如果您使用的是表或者集合视图,您可以对单元格执行相同的操作。对您想要的视图设置为Loadable
。然后,您必须实现ContentLoaderDataSource
来提供ContentLoader绘制加载对象所需的一些数据。
extension TableViewController: ContentLoaderDataSource {
/// Number of sections you would like to show in loader
func numSections(in contentLoaderView: UIView) -> Int {
return 1
}
/// Number of rows you would like to show in loader
func contentLoaderView(_ contentLoaderView: UIView, numberOfItemsInSection section: Int) -> Int {
return 10
}
/// Cell reuse identifier you would like to use (ContenLoader will search loadable objects here!)
func contentLoaderView(_ contentLoaderView: UIView, cellIdentifierForItemAt indexPath: IndexPath) -> String {
return "MyCellReuseIdentifier"
}
}
格式
您可以使用自己的参数来格式化ContentLoader
。查看默认值
var format = ContentLoaderFormat()
/// Loader objects color
format.color = UIColor.lightGray
/// Loader objects corner radius
format.radius = 5
/// Loader animation type
format.animation = .fade
开始和停止加载
简单 ;)
view.startLoading()
// or
view.startLoading(format: format)
view.hideLoading()
针对表格或集合视图
tableView.startLoading()
// or
tableView.startLoading(format: format)
tableView.hideLoading()
动画类型
渐变
此类型在内容加载时会进行渐变动画。
ContentLoaderAnimation.fade
渐变色
此类型在内容加载时会进行渐变色动画(即将推出)
ContentLoaderAnimation.gradient(UIColor, UIColor)
(起始颜色,结束颜色)
使用ContentLoader的应用
如果你使用 ContentLoader
,我很乐意听到你的信息,并在这里推出你的应用!
作者
Alberto Aznar,[email protected] 基于 Juanpe Catalán的Skeleton View。
贡献
随时欢迎提出合作意见
- fork它!
- 创建您的功能分支:
git checkout -b my-new-feature
- 提交您的更改:
git commit -am '添加一些功能'
- 将更改推送到分支:
git push origin my-new-feature
- 提交拉取请求:D
许可证
ContentLoader在MIT许可证下可用。更多信息请参阅LICENSE文件。