Latest 1.0.0
Homepage https://github.com/reesun1130/SYRefreshSwift
License MIT
Platforms ios 8.0, requires ARC
Authors

SY Refresh Swift,简单易用的下拉刷新组件,低耦合,使用简单,几行代码即可实现下拉刷新,任何UIScrollView及子类可使用。

请使用UIScrollView及子类初始化SYRefresh

  1. 属性
    • 各种状态下的提示信息(可以选择设置ready、pulling、refreshing)
      • ready:松开立即刷新(默认)
      • pulling:下拉即可刷新(默认)
      • refreshing:努力刷新中…(默认)
    • imagePulling:展示的图片(默认箭头)
  2. 方法
    • func beginRefreshing() -> Void(开始刷新,一般不需要手动调用)
    • func endRefreshing() -> Void(数据获取完成,调用这个方法以结束刷新动画)
    • func isRefreshing() -> Bool(是否正在刷新,默认NO)
    • func setImagePulling(imagePull:UIImage!) -> Void(设置图片,默认arrowDown)
  3. 用法简单(几行代码即可实现下拉刷新)
refresh = SYRefresh.init(scrollView: tableview)
//refresh.pulling = "pulling"
//refresh.ready = "ready"
refresh.refreshing = "refreshing"
refresh.addTarget(self, action: #selector(refreshitems), for: .valueChanged)

Example

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    var tableview : UITableView!
    var items : Array<String>!
    var refresh : SYRefresh!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        items = ["s","w","i","f","t"]

        tableview = UITableView.init(frame: self.view.bounds, style: .plain)
        tableview.dataSource = self
        tableview.delegate = self
        self.view.addSubview(tableview)

        //刷新组件
        refresh = SYRefresh.init(scrollView: tableview)
        refresh.addTarget(self, action: #selector(refreshitems), for: .valueChanged)
        //refresh.pulling = "pulling"
        //refresh.ready = "ready"
        refresh.refreshing = "refreshing"
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let id = "idcell"
        var cell = tableView.dequeueReusableCell(withIdentifier: id)

        if cell == nil {
            cell = UITableViewCell.init(style: .default, reuseIdentifier: id)
        }
        cell?.textLabel?.text = items[indexPath.row]

        return cell!
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(items[indexPath.row])
    }

    func refreshitems() -> Void {
        items.removeAll()

        let count : UInt32 = (arc4random() % 10) + 1

        for i : UInt32 in 0 ..< count {
            items.append(String.init(i))
        }

        let delayTime = DispatchTime.now() + Double(Int64(Double(NSEC_PER_SEC) * 2.5)) / Double(NSEC_PER_SEC)
        DispatchQueue.main.asyncAfter(deadline: delayTime) { () -> Void in
            //刷新结束
            self.refresh.endRefreshing()
            self.tableview.reloadData()
        }
    }
}

UI

intro png

Installation

CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like JSPatch in your projects. See the "Getting Started" guide for more information.

# Your Podfile
platform :ios, '8.0'
pod 'SYRefreshSwift'

Manually

  1. 复制 SYRefresh.swift arrowDown.png 到你的project
  2. 直接拷贝 SYRefreshSwift/目录到你的project.

Usage

Swift

  1. 使用你的UIScrollView或者子类初始化

    refresh = SYRefresh.init(scrollView: tableview)

  2. refresh添加target

    refresh.addTarget(self, action: #selector(refreshitems), for: .valueChanged)

  3. optional可选设置

    • 设置刷新各种状态下的标题
      refresh.pulling = "pulling"
      refresh.ready = "ready"
      refresh.refreshing = "refreshing"

    • 设置显示图片
      refresh.setImagePulling(imagePull:)
  4. 刷新结束,停止动画 refresh.endRefreshing()

Enviroment

  • iOS 8+
  • Swift
  • Support armv7/armv7s/arm64

Misc

Author

License

This code is distributed under the terms and conditions of the MIT license.

Contribution guidelines

NB! If you are fixing a bug you discovered, please add also a unit test so I know how exactly to reproduce the bug before merging.

Latest podspec

{
    "name": "SYRefreshSwift",
    "version": "1.0.0",
    "summary": "SY Refresh Swiftuff0cu4e0bu62c9u5237u65b0u7ec4u4ef6uff0cu4f7fu7528u7b80u5355uff0cu51e0u884cu4ee3u7801u5373u53efu5b9eu73b0u4e0bu62c9u5237u65b0uff0cu4efbu4f55UIScrollViewu53cau5b50u7c7bu53efu4f7fu7528u3002",
    "description": "SY Refresh Swiftuff0cu7b80u5355u6613u7528u7684u4e0bu62c9u5237u65b0u7ec4u4ef6uff0cu4f4eu8026u5408uff0cu4f7fu7528u7b80u5355uff0cu51e0u884cu4ee3u7801u5373u53efu5b9eu73b0u4e0bu62c9u5237u65b0uff0cu4efbu4f55UIScrollViewu53cau5b50u7c7bu53efu4f7fu7528u3002",
    "homepage": "https://github.com/reesun1130/SYRefreshSwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE_SY.txt"
    },
    "authors": {
        "reesun": "[email protected]"
    },
    "source": {
        "git": "https://github.com/reesun1130/SYRefreshSwift.git",
        "tag": "1.0.0"
    },
    "source_files": "SYRefreshSwift/*.swift",
    "resources": "SYRefreshSwift/*.{png,bundle}",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This