Giter Club home page Giter Club logo

hmrefresh's Introduction

HMRefresh

Build Status CocoaPods Compatible Platform

轻量级的上拉/下拉刷新控件

功能

  • UIRefreshControl 完全一致的接口调用方式,上手容易
  • 面向协议编程,能够方便灵活地自定义视图
  • 支持 UITableViewUICollectionView 的上/下拉刷新,不占用 HeaderViewFooterView
  • 预加载数据功能,当显示最后一个 cell 时,能够自动刷新后续数据,网络流畅时,用户看不到上拉视图,提供更加流畅的用户体验
  • 无数据设置,当重复上拉刷新数据没有结果时,会停止上拉刷新,不会频繁发起网络请求

屏幕截图

系统支持

  • iOS 7.0+
  • Xcode 7.0

安装

CocoaPods

  • 进入终端,cd 到项目目录,输入以下命令,建立 Podfile
$ pod init
  • 在 Podfile 中输入以下内容:
platform :ios, '7.0'
use_frameworks!

target 'ProjectName' do
pod 'HMRefresh'
end
  • 在终端中输入以下命令,安装或升级 Pod
# 安装 Pod,第一次使用
$ pod install

# 升级 Pod,后续使用
$ pod update

使用

Objective-C

  • 导入框架
@import HMRefresh;
  • 在 TableViewController 的 viewDidLoad 中设置刷新控件
- (void)viewDidLoad {
    [super viewDidLoad];

    // 添加刷新控件
    HMRefreshControl *refreshControl = [[HMRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(loadData:) forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview:refreshControl];

    [self loadData:refreshControl];
}
  • 刷新数据方法
- (void)loadData:(HMRefreshControl *)refreshControl {

    // 开始刷新
    [refreshControl beginRefreshing];
    [self.dataModal loadData:refreshControl.isPullupRefresh completion:^{
        // 结束刷新
        [refreshControl endRefreshing];

        // 刷新数据
        [self.tableView reloadData];
    }];
}

自定义视图

  • 使用 XIB 或 Storyboard 建立上拉/下拉刷新视图
  • 在自定义视图的头文件中遵守协议
@interface DemoRefreshView : UIView <HMRefreshViewDelegate>

@end
  • 代码连线到私有扩展中
/// 刷新指示器
@property (nonatomic, weak) IBOutlet UIActivityIndicatorView *refreshIndicator;
/// 下拉提示图像
@property (nonatomic, weak) IBOutlet UIImageView *pulldownIcon;
/// 提示标签
@property (nonatomic, weak) IBOutlet UILabel *tipLabel;
/// 刷新时间标签
@property (nonatomic, weak) IBOutlet UILabel *timeLabel;

提示:如果不需要可以不连线,不过属性仍然需要保留

Swift

  • 导入框架
import HMRefresh
  • 在 TableViewController 的 viewDidLoad 中设置刷新控件
override func viewDidLoad() {
    super.viewDidLoad()

    let refreshControl = HMRefreshControl()
    self.tableView.addSubview(refreshControl)

    refreshControl.addTarget(self, action: "loadData:", forControlEvents: .ValueChanged)
}
  • 刷新数据方法
@objc private func loadData(refreshControl: HMRefreshControl) {

    refreshControl.beginRefreshing()
    dataModel.loadData(refreshControl.isPullupRefresh) {
        refreshControl.endRefreshing()

        self.tableView.reloadData();
    }
}

hmrefresh's People

Contributors

liufan321 avatar readmecritic avatar heima-dev avatar

Watchers

ZhaoLei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.