MJRefresh 的使用

2020-07-09  本文已影响0人  __season____

github:https://github.com/CoderMJLee/MJRefresh

一、MJRefresh的类结构图

MJRefresh的类结构图

二、举例

self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
   //当自动进入刷新状态时调用此Block
}];

//设置回调(进入刷新状态后,调用target的动作,即调用[self loadNewData]) 
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];

// 立即进入刷新状态 
[self.tableView.mj_header beginRefreshing];

01 默认刷新
MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// 设置动画图像的普通状态
[header setImages:idleImages forState:MJRefreshStateIdle];
//设置动画图像的拖动状态(进入放松即刷新状态)
[header setImages:pullingImages forState:MJRefreshStatePulling];
// 设置动画图片的刷新状态 
[header setImages:refreshingImages forState:MJRefreshStateRefreshing];
self.tableView.mj_header = header;

02 动画图片
//隐藏时间
header.lastUpdatedTimeLabel.hidden = YES;
03 隐藏时间
//隐藏时间
header.lastUpdatedTimeLabel.hidden = YES;
// 隐藏状态
header.stateLabel.hidden = YES;
隐藏状态和时间
// 设置文字
[header setTitle:@"Pull down to refresh" forState:MJRefreshStateIdle];
[header setTitle:@"Release to refresh" forState:MJRefreshStatePulling];
[header setTitle:@"Loading ..." forState:MJRefreshStateRefreshing];

// 设置文字大小
header.stateLabel.font = [UIFont systemFontOfSize:15];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];

// Set textColor
header.stateLabel.textColor = [UIColor redColor];
header.lastUpdatedTimeLabel.textColor = [UIColor blueColor];

(下拉刷新05-自定义文字)
self.tableView.mj_header = [MJDIYHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];

下拉刷新06-自定义刷新控件
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
    //Call this Block When enter the refresh status automatically
}];

//或者
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
01 上拉默认刷新
MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];

// 设置刷新图像
[footer setImages:refreshingImages forState:MJRefreshStateRefreshing];

self.tableView.mj_footer = footer;
02 动画上拉刷新
// 隐藏刷新状态的标题
footer.refreshingTitleHidden = YES;
// If does have not above method,then use //footer.stateLabel.hidden = YES;
03 隐藏刷新状态的标题
//成为NoMoreData的状态
[footer noticeNoMoreData];
04 全部加载完毕
// Set title
[footer setTitle:@"Click or drag up to refresh" forState:MJRefreshStateIdle];
[footer setTitle:@"Loading more ..." forState:MJRefreshStateRefreshing];
[footer setTitle:@"No more data" forState:MJRefreshStateNoMoreData];

// Set font
footer.stateLabel.font = [UIFont systemFontOfSize:17];

// Set textColor
footer.stateLabel.textColor = [UIColor blueColor];
05 自定义文字
//Hidden current control of the pull to refresh
self.tableView.mj_footer.hidden = YES;
06 加载后隐藏
//自动回弹的上拉
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
自动回弹的上拉 01
MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];

//设置动画图像的正常状态
[footer setImages:idleImages forState:MJRefreshStateIdle];
//设置动画图像的拖动状态(松开即进入刷新状态) 
[footer setImages:pullingImages forState:MJRefreshStatePulling];
// 设置动画图像的刷新状态
[footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
self.tableView.mj_footer = footer;
自动回弹的上拉 02
self.tableView.mj_footer = [MJDIYAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
//实现参考MJDIYAutoFooter.h和MJDIYAutoFooter.m

自定义刷新控件
self.tableView.mj_footer = [MJDIYBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
//实现参考MJDIYBackFooter.h和MJDIYBackFooter.m
自定义刷新控件(自动回弹)
// 下拉刷新
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
   //当自动进入刷新状态时调用此块
}];

// 上拉刷新
self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
   //当自动进入刷新状态时调用此块
}];
上下拉刷新
// The trailer refresh
self.collectionView.mj_trailer = [MJRefreshNormalTrailer trailerWithRefreshingBlock:^{
   //当自动进入刷新状态时调用此块
}];
MJRefresh 演示
//添加下拉刷新控件
self.webView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
   //当自动进入刷新状态时调用此块
}];
WKWebView 添加下拉刷新控件

提醒:

上一篇 下一篇

猜你喜欢

热点阅读