- The easiest way to use pull-to-refresh
- 用法最简单的下拉刷新框架:一行代码搞定
UIScrollView
、UITableView
、UICollectionView
、UIWebView
- cocoapods导入:
pod 'MJRefresh'
- 手动导入:
- 将
MJRefreshExample/MJRefreshExample/MJRefresh
文件夹中的所有文件拽入项目中
- 导入主头文件:
#import "MJRefresh.h"
MJRefresh.bundle
MJRefresh.h
MJRefreshComponent.h MJRefreshComponent.m
MJRefreshConst.h MJRefreshConst.m
MJRefreshFooter.h MJRefreshFooter.m
MJRefreshGifFooter.h MJRefreshGifFooter.m
MJRefreshGifHeader.h MJRefreshGifHeader.m
MJRefreshHeader.h MJRefreshHeader.m
MJRefreshLegendFooter.h MJRefreshLegendFooter.m
MJRefreshLegendHeader.h MJRefreshLegendHeader.m
UIScrollView+MJExtension.h UIScrollView+MJExtension.m
UIScrollView+MJRefresh.h UIScrollView+MJRefresh.m
UIView+MJExtension.h UIView+MJExtension.m
![(App03)](https://camo.githubusercontent.com/26a4513aae95928efcb9b07c9f66c1a0234032efd50630d16f0c3b4259b466c0/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530342f3039313533353433393436363731382e706e67)
* 由于这个框架的功能较多,就不写具体文字描述其用法
* 大家可以直接参考示例中的MJTableViewController和MJCollectionViewController,更为直观快速
![(下拉刷新01-传统)](https://camo.githubusercontent.com/c6261a8e2ad108ad80a8adb33b944d2335fe72eb90fcb5d65a6976fb1a13fbe3/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035383431353339323335332e676966)
// 添加传统的下拉刷新
[self.tableView addLegendHeaderWithRefreshingBlock:^{
// 进入刷新状态后会自动调用这个block
}];
或
// 添加传统的下拉刷新
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
[self.tableView addLegendHeaderWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// 马上进入刷新状态
[self.tableView.header beginRefreshing];
![(下拉刷新02-动画图片)](https://camo.githubusercontent.com/83118ebefcddf2b0587670c32da772ab3ed289101f9b15418e90419f6b1d4255/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035383437313830323334322e676966)
// 添加动画图片的下拉刷新
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
[self.tableView addGifHeaderWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// 设置普通状态的动画图片
[self.tableView.gifHeader setImages:idleImages forState:MJRefreshHeaderStateIdle];
// 设置即将刷新状态的动画图片(一松开就会刷新的状态)
[self.tableView.gifHeader setImages:pullingImages forState:MJRefreshHeaderStatePulling];
// 设置正在刷新状态的动画图片
[self.tableView.gifHeader setImages:refreshingImages forState:MJRefreshHeaderStateRefreshing];
![(下拉刷新03-隐藏时间)](https://camo.githubusercontent.com/7e897204b5985ead2652ce676e04a4eee0f599ce4effe466a2d78f1444bdcbad/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035383532343737383736302e676966)
// 隐藏时间
self.tableView.header.updatedTimeHidden = YES;
![(下拉刷新04-隐藏状态和时间01)](https://camo.githubusercontent.com/3945655f9f18174de7222dbc2d56543d55bbc612c8df8379f845951cbe8c20d1/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035383537363032343839332e676966)
// 隐藏时间
self.tableView.header.updatedTimeHidden = YES;
// 隐藏状态
self.tableView.header.stateHidden = YES;
![(下拉刷新05-隐藏状态和时间02)](https://camo.githubusercontent.com/16af98c6203d1c4b7e0cabb4e16f4b821bdd432e399927fe9e7ea49b10b52950/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035393033303836353036392e676966)
![(下拉刷新06-自定义文字)](https://camo.githubusercontent.com/abc7e0cbc461a4a9c04b3364806fa203b2074c398e2e70dab53903b2ef4242f4/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3038313031343235343631333137392e676966)
// 设置文字
[self.tableView.header setTitle:@"Pull down to refresh" forState:MJRefreshHeaderStateIdle];
[self.tableView.header setTitle:@"Release to refresh" forState:MJRefreshHeaderStatePulling];
[self.tableView.header setTitle:@"Loading ..." forState:MJRefreshHeaderStateRefreshing];
// 设置字体
self.tableView.header.font = [UIFont systemFontOfSize:15];
// 设置颜色
self.tableView.header.textColor = [UIColor redColor];
![(上拉刷新01-传统)](https://camo.githubusercontent.com/d4e55e63cbe51db132b46452e9af561d256d52732dd1a4ab11a0d2b643630215/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313130313437323734353336312e676966)
// 添加传统的上拉刷新
[self.tableView addLegendFooterWithRefreshingBlock:^{
// 进入刷新状态后会自动调用这个block
}];
或
// 添加传统的上拉刷新
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
[self.tableView addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
![(上拉刷新02-动画图片)](https://camo.githubusercontent.com/086f70314ec4e12936a512ecfbe614d541078435305ea930edbee0f62f453890/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035363337323734333938382e676966)
// 添加动画图片的上拉刷新
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
[self.tableView addGifFooterWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// 设置正在刷新状态的动画图片
self.tableView.gifFooter.refreshingImages = refreshingImages;
![(上拉刷新03-隐藏状态01)](https://camo.githubusercontent.com/0970f67a3ea99aab3d0843995a301d59a0a4e8b8d6fe46b1b0b3d45c49dd9712/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313130323032383336353531372e676966)
// 隐藏状态
self.tableView.footer.stateHidden = YES;
![(上拉刷新04-隐藏状态02)](https://camo.githubusercontent.com/48a3b994beaf5783ce776a62b737dc3d27507787e7516b6aa8d63585d9af9153/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035383039333532353038352e676966)
![(上拉刷新05-全部加载完毕)](https://camo.githubusercontent.com/e1d612a69ca99c54c44949081bd21c078916233ac7341fb46570295aa9c6b9c4/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035383137323131373432302e676966)
// 变为没有更多数据的状态
[self.tableView.footer noticeNoMoreData];
![(上拉刷新06-禁止自动加载)](https://camo.githubusercontent.com/9d699bad44e45f9874eaba279c142ab565c18146ac9f40b10c148b0438115bd2/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035383233373131393533392e676966)
// 禁止自动加载
self.tableView.footer.automaticallyRefresh = NO;
![(上拉刷新07-自定义文字)](https://camo.githubusercontent.com/c263b5e9514099b62ed8a3a4f86be3a6862ad7a20e6a5f0a710720e1fbb5188b/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3038313031343339353535323631382e676966)
// 设置文字
[self.tableView.footer setTitle:@"Click or drag up to refresh" forState:MJRefreshFooterStateIdle];
[self.tableView.footer setTitle:@"Loading more ..." forState:MJRefreshFooterStateRefreshing];
[self.tableView.footer setTitle:@"No more data" forState:MJRefreshFooterStateNoMoreData];
// 设置字体
self.tableView.footer.font = [UIFont systemFontOfSize:17];
// 设置颜色
self.tableView.footer.textColor = [UIColor blueColor];
![(上拉刷新08-加载后隐藏)](https://camo.githubusercontent.com/b20a5833a877442c0794421a3735631195f45dc4ca6c2cdc42b70f5961f47c9d/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313035383336303339353430362e676966)
// 隐藏当前的上拉刷新控件
self.tableView.footer.hidden = YES;
![(UICollectionView01-上下拉刷新)](https://camo.githubusercontent.com/d6d3573e1cd92bc782dadad1528fc5b2f332df0cda1d661ef8082ba74636e4fc/687474703a2f2f696d616765732e636e6974626c6f672e636f6d2f626c6f67323031352f3439373237392f3230313530332f3036313130333238323839373232332e676966)
// 添加传统的下拉刷新
[self.collectionView addLegendHeaderWithRefreshingBlock:^{
// 进入刷新状态后会自动调用这个block
}];
// 添加传统的上拉刷新
[self.collectionView addLegendFooterWithRefreshingBlock:^{
// 进入刷新状态后会自动调用这个block
}];
![(UIWebView01-下拉刷新)](https://camo.githubusercontent.com/bde6d84d3cc10dbdfe956c68fb2af75d4b5fac78d66c9acc73728134a19a8571/687474703a2f2f7777312e73696e61696d672e636e2f6d77313032342f38303063646639636a77316571327a6a7a7537386e67323038773066793471702e676966)
// 添加下拉刷新控件
[self.webView.scrollView addLegendHeaderWithRefreshingBlock:^{
// 进入刷新状态后会自动调用这个block
}];
- 本框架纯ARC,兼容的系统>=iOS6.0、iPhone\iPad横竖屏
- 如果在使用过程中遇到BUG,希望你能Issues我,谢谢(或者尝试下载最新的框架代码看看BUG修复没有)
- 如果在使用过程中发现功能不够用,希望你能Issues我,我非常想为这个框架增加更多好用的功能,谢谢
- 如果你想为MJRefresh输出代码,请拼命Pull Requests我
- 一起携手打造天朝乃至世界最好用的刷新框架,做天朝程序员的骄傲
- 如果你开发的应用中用到了MJRefresh,希望你能到CocoaControls添加你应用的iTunes路径,我将会安装使用你的应用,并且根据众多应用的使用情况,对MJRefresh进行一个更好的设计和完善,提供更多好用的功能,谢谢
- 步骤01(微信是举个例子,百度“你的应用名称 itunes”)
![(step01)](https://camo.githubusercontent.com/c43397ad044f676fe1bbb2b6137ba96616969aef81dff60f4d69c52643420a58/687474703a2f2f7777342e73696e61696d672e636e2f6d77313032342f3830306364663963747731657130766969763572736a3230736d3065613431742e6a7067)
- 步骤02
![(step02)](https://camo.githubusercontent.com/13a391c4d99057c294849f32f9748142baa30a68ea2bb65589093072797a69bf/687474703a2f2f7777322e73696e61696d672e636e2f6d77313032342f383030636466396374773165713076696c656a786c6a32307475306d653761302e6a7067)
- 步骤03
![(step03)](https://camo.githubusercontent.com/9f1c2a1dd1e5bbfef36888ab18961382a5d7af6ed1a7a1da08c59a4f2c823940/687474703a2f2f7777312e73696e61696d672e636e2f6d77313032342f383030636466396374773165713076696f63706f356a3230776330646330756e2e6a7067)
- 步骤04
![(step04)](https://camo.githubusercontent.com/bea388dc9c35cf433de0de5b1d174bca835c9bc35d8800afe15bb7473d9a3c8c/687474703a2f2f7777332e73696e61696d672e636e2f6d77313032342f3830306364663963747731657130766972313337786a323073693067657767752e6a7067)