swift3自定义下拉刷新控件(二)QQ弹簧效果

来源:互联网 发布:淘宝网什么时候搞活动 编辑:程序博客网 时间:2024/05/16 02:01

1、请在命令行输入 

pod search tgrefreshswift


2、弹出下面提示说明可以使用


3、在你的podfile中导入tgrefreshswift

即这一句

pod 'TGRefreshSwift'

# Uncomment the next line to define a global platform for your project# platform :ios, '9.0'target 'TGRefreshSwiftDemo' do  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks  use_frameworks!  # Pods for TGRefreshSwiftDemopod 'TGRefreshSwift'end

过程图



4、使用控件

////  ViewController.swift//  TGRefreshSwiftDemo////  Created by targetcloud on 2017/6/26.//  Copyright © 2017年 targetcloud. All rights reserved.//import UIKitimport TGRefreshSwiftclass ViewController: UIViewController {    @IBOutlet weak var tv: UITableView!    fileprivate let identifier = "cell"    fileprivate var dataCount: Int = 10    override func viewDidLoad() {        super.viewDidLoad()        tv.dataSource = self        tv.delegate = self        tv.tableFooterView = UIView()        tv.allowsSelection = false                self.automaticallyAdjustsScrollViewInsets=false                builderRecommend5()    }    @objc fileprivate func loadDataSenior(){        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+2) {            let isSuccess = arc4random_uniform(3) % 2 == 0            let count = isSuccess ? arc4random_uniform(20) : 0            self.dataCount = count>0 ? Int(count) : self.dataCount            self.tv.tg_header?.refreshResultStr = count>0 ? "成功刷新到\(count)条数据,来自TGRefreshSwift" : "请先在Github上Star本控件:-)"            self.tv.tg_header?.isSuccess = isSuccess            isSuccess ? self.tv.reloadData() : ()            self.tv.tg_header?.endRefreshing()        }    }}extension ViewController{    //QQ效果    fileprivate func builderRecommend(){        self.tv.tg_header = TGRefreshSwift.refresh(self, #selector(loadDataSenior))        self.tv.tg_header?.beginRefreshing()    }        //QQ效果    fileprivate func builderRecommend2(){        self.tv.tg_header = TGRefreshSwift.refresh()        self.tv.tg_header?.addTarget(self, action: #selector(loadDataSenior), for: .valueChanged)        self.tv.tg_header?.beginRefreshing()    }        //一般平常效果    fileprivate func builderRecommend3(){        self.tv.tg_header = TGRefreshSwift.refresh(self, #selector(loadDataSenior)){(refresh) in            refresh.tg_kind(.Common)        }        self.tv.tg_header?.beginRefreshing()    }        //更多配置    fileprivate func builderRecommend4(){        self.tv.tg_header = TGRefreshSwift.refresh(self, #selector(loadDataSenior)){(refresh) in            refresh.tg_refreshResultBgColor(UIColor.orange.withAlphaComponent(0.8))                .tg_fadeinTime(2)                .tg_verticalAlignment(.Midden)                .tg_fadeoutTime(1)                .tg_bgColor(UIColor(white:0.8,alpha:1))        }        self.tv.tg_header?.beginRefreshing()    }        //扩展用法    fileprivate func builderRecommend5(){        self.tv.tg_header = TGRefreshSwift.refresh(self, #selector(loadDataSenior),44,UIImageView(image: UIImage(named: "profile_cover_background")) ){(refresh) in            refresh.tg_refreshResultBgColor(UIColor.orange.withAlphaComponent(0.8))                .tg_verticalAlignment(.Midden)                .tg_tinColor(UIColor.white)                .tg_tipLabelFontSize(13)                .tg_resultLabelFontSize(15)                .tg_tipFailStyle(.tipInfoWhite)                .tg_tipOKStyle(.tipOKWhite)                .tg_fadeinTime(1)                .tg_fadeoutTime(0.5)                .tg_bgColor(UIColor(white:0.8,alpha:1))        }        self.tv.tg_header?.beginRefreshing()    }}extension ViewController: UITableViewDataSource,UITableViewDelegate{    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {        return dataCount    }        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {        var cell: UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: identifier)        if cell == nil {            cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: identifier)        }        cell?.textLabel?.text = "第\(indexPath.row)行测试数据"        return cell!    }        func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {        return 44    }}


完整使用说明请参见

https://github.com/targetcloud/TGRefreshSwift