Skip to content

Detailscool/YHRefresh

Repository files navigation

YHRefresh

Version license Platform Language

Introduction

Inspired By MJRefresh

A refreshing helper written in Swift, which can be used to refresh easily.Still working on making it more perfectly.Looking forward to any positive suggestion
Swift 5.4.2 Supporting Now...
一款简单易用的Swift版上拉或者下拉刷新...还在努力不断完善中...欢迎任何建设性PR
现已支持Swift 5.4.2

Components

Cocoapods

edit Podfile 编辑Podfile文件:

  use_frameworks!
  pod 'YHRefresh', '~> 0.5.0’

then run in terminal 在终端运行:

  pod install --no-repo-update

Usage

   // AppDelegate.m
   import YHRefresh
   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Switf 4 新特性,取消initialize方法后需手动swizlling method
        UIScrollView.initialize()
        
        return true
    }


    // ViewController.m
    import YHRefresh
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.yh_header = YHRefreshNormalHeader.header(self, selector: "load") as! YHRefreshNormalHeader
        tableView.yh_header.beginRefreshing()
    }
    
    func load() {
        
        //模拟网络请求
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), { () -> Void in
	
	      /*网络回调处理*/
	    
	      /*刷新数据*/
	      self.tableView.reloadData()
	      /*结束刷新*/
	      self.tableView.yh_header?.endRefreshing()
    
        }
    }
    
    -----------------------------------分割线-----------------------------------
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.yh_footer = YHRefreshNormalFooter.footer(self, selector: "loadMore") as! YHRefreshNormalFooter
        
    }
    
    func loadMore() {
        
        //模拟网络请求
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), { () -> Void in
        
 	      /*网络回调处理*/
 	    
	      /*刷新数据*/
	      self.tableView.reloadData()
	      /*结束刷新*/
	      self.tableView.yh_footer?.endRefreshing()
	    
	      /*条件判断是否已经数据最大,若是显示没有更多数据*/
 	      //self.tableView.yh_footer?.showNoMoreData()

        }
    }
    -----------------------------------分割线-----------------------------------
    注:header和footer可以同时用,但请回避两者同时刷新~!

Effect

①YHRefreshNormalHeader

②YHRefreshSpringHeader

③YHRefreshGifHeader

④YHRefreshNormalFooter

⑤YHRefreshAutoFooter

⑥YHRefreshGifFooter

Last Version Requirements

  • Swift 5.4
  • Xcode 12.0++

License

Copyright (c) 2016 YuanHui Lee [email protected]. See the LICENSE file for more info.