PullToRefreshDSL 1.0.0

PullToRefreshDSL 1.0.0

Salmaan Ahmed 维护。




PullToRefreshDSL

一行代码即可向任何 UIScrollView 子类的头部或尾部添加拉取刷新视图,例如 Collection TableView。

Swift 5 Version License Platform Country

示例

要运行示例项目,请先克隆仓库,然后从 Demo 目录运行 pod install

演示

拉取刷新是几乎所有移动应用的基本功能,但它并不那么容易实现。它还有一些限制和固有的问题。代码重复是促使我开发这个库的主要原因之一。

受到《DSL 模式》和像 SnapKit 那样易用性的启发,这个库也使用相同的模式。关键字是 ptr,用于访问所有的 PullToRefresh 属性和方法。



使用

第 1 步: 启用 PullToRefresh🚀

// You only have to add the callback, rest is taken care of
tableView.ptr.headerCallback = { [weak self] in // weakify self to avoid strong reference
    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) { // your network call
        self?.tableView.ptr.isLoadingHeader = false // setting false will hide the view
    }
}

第 2 步: 禁用 PullToRefresh🤯

// Yeah thats all, just set it to nil
tableView.ptr.headerCallback = nil // it is disabled by default

第 3 步: 欣赏!就这样,你已经完成了😎

享受 PullToRefresh,为用户提供出色的用户体验。简单,不是吗?

其他设置:可定制性🤔

您可以使用自己的视图/活动指示器,但别忘了添加 高度

tableView.ptr.headerHeight = 50 // Set its height
tableView.ptr.headerView = yourCustomView() // Set your customView

您还可以将 PullToRefresh 添加到 scrollView/tableView/collectionView 的底部

tableView.ptr.footerCallback = { } // add callback to enable
tableView.ptr.footerCallback = nil // set to nil to disable

您的 scrollView 会使 PullToRefresh 视图优雅地隐藏/显示

tableView.ptr.animationDuration = 0.3 // yes you can set it as well

您还可以使用以下属性在任何时候显示/隐藏视图

// Show Header
tableView.ptr.isLoadingHeader = true
tableView.ptr.showHeader()

// Hide Header
tableView.ptr.isLoadingHeader = false
tableView.ptr.hideHeader()

// Show Footer
tableView.ptr.isLoadingFooter = true
tableView.ptr.showFooter()

// Hide Footer
tableView.ptr.isLoadingFooter = false
tableView.ptr.hideFooter()

// NOTE: callbacks will only be fired when using property to show PullToRefresh view

安装

HorizontalCalendar 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile 中

pod 'PullToRefreshDSL'

作者

Salmaan Ahmed, [email protected]

许可证

HorizontalCalendar 遵循 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。