- Installation with CocoaPods:
pod 'MJRefresh'
- Manual import:
- Drag All files in the
MJRefresh
folder to project
- Import the main file:
#import "MJRefresh.h"
Base Custom
MJRefresh.bundle MJRefresh.h
MJRefreshConst.h MJRefreshConst.m
UIScrollView+MJExtension.h UIScrollView+MJExtension.m
UIScrollView+MJRefresh.h UIScrollView+MJRefresh.m
UIView+MJExtension.h UIView+MJExtension.m
- More information of App can focus on:M了个J-博客园
The Class Structure Chart of MJRefresh
![](https://camo.githubusercontent.com/4a86d398d981df5dc845042b92c6d785d0d486b4/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3133323233323435363133393137372e706e67)
The class of red text
in the chart:You can use them directly
- The drop-down refresh control types
- Normal:
MJRefreshNormalHeader
- Gif:
MJRefreshGifHeader
- The pull to refresh control types
- Auto refresh
- Normal:
MJRefreshAutoNormalFooter
- Gif:
MJRefreshAutoGifFooter
- Auto Back
- Normal:
MJRefreshBackNormalFooter
- Gif:
MJRefreshBackGifFooter
The class of non-red text
in the chart:For inheritance,to use DIY the control of refresh
- About how to DIY the control of refresh,You can refer the Class in below Chart
![](https://camo.githubusercontent.com/73223b12a7f9a6e439e3d9176636de0eacd8dfc0/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313335383135393130373839332e706e67)
MJRefreshComponent.h
/** The Base Class of refresh control */
@interface MJRefreshComponent : UIView
#pragma mark - Control the state of Refresh
/** BeginRefreshing */
- (void)beginRefreshing;
/** EndRefreshing */
- (void)endRefreshing;
/** IsRefreshing */
- (BOOL)isRefreshing;
#pragma mark - Other
/** According to the drag ratio to change alpha automatically */
@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;
@end
MJRefreshHeader.h
@interface MJRefreshHeader : MJRefreshComponent
/** Creat header */
+ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
/** Creat header */
+ (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
/** This key is used to storage the time that the last time of drown-down successfully */
@property (copy, nonatomic) NSString *lastUpdatedTimeKey;
/** The last time of drown-down successfully */
@property (strong, nonatomic, readonly) NSDate *lastUpdatedTime;
/** Ignored scrollView contentInset top */
@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop;
@end
MJRefreshFooter.h
@interface MJRefreshFooter : MJRefreshComponent
/** Creat footer */
+ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
/** Creat footer */
+ (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
/** NoticeNoMoreData */
- (void)noticeNoMoreData;
/** ResetNoMoreData(Clear the status of NoMoreData ) */
- (void)resetNoMoreData;
/** Ignored scrollView contentInset bottom */
@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom;
/** Automaticlly show or hidden by the count of data(Show-have data,Hidden- no data) */
@property (assign, nonatomic) BOOL automaticallyHidden;
@end
MJRefreshAutoFooter.h
@interface MJRefreshAutoFooter : MJRefreshFooter
/** Is Automatically Refresh(Default is Yes) */
@property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh;
/** When there is much at the bottom of the control is automatically refresh(Default is 1.0,Is at the bottom of the control appears in full, will refresh automatically) */
@property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent;
@end
Reference
* Due to there are more functions of this framework,Don't write specific text describe its usage
* You can directly reference examples MJTableViewController、MJCollectionViewController、MJWebViewController,More intuitive and fast.
![](https://camo.githubusercontent.com/f4d0ad2b6a908cb719e88613ec995d0707471159/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313334353437303034383132302e706e67)
The drop-down refresh 01-Default
self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
或
// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadNewData])
self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// Enter the refresh status immediately
[self.tableView.header beginRefreshing];
![(下拉刷新01-普通)](https://camo.githubusercontent.com/15577b87be4403d9e2ede4d5cd5b9fccbd1d03ae/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230343334333438363135312e676966)
The drop-down refresh 02-Animation image
// Set the callback(一Once you enter the refresh status,then call the action of target,that is call [self loadNewData])
MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// Set the ordinary state of animated images
[header setImages:idleImages forState:MJRefreshStateIdle];
// Set the pulling state of animated images(Enter the status of refreshing as soon as loosen)
[header setImages:pullingImages forState:MJRefreshStatePulling];
// Set the refreshing state of animated images
[header setImages:refreshingImages forState:MJRefreshStateRefreshing];
// Set header
self.tableView.mj_header = header;
![(下拉刷新02-动画图片)](https://camo.githubusercontent.com/911191d46157ea3961728b16696aea4440ffeb92/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230343430323233383338392e676966)
The drop-down refresh 03-Hide the time
// Hide the time
header.lastUpdatedTimeLabel.hidden = YES;
![(下拉刷新03-隐藏时间)](https://camo.githubusercontent.com/c32d67233572a1d3a8bd3a5214dde01ab8832db7/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230343435363133323934342e676966)
The drop-down refresh 04-Hide status and time
// Hide the time
header.lastUpdatedTimeLabel.hidden = YES;
// Hide the status
header.stateLabel.hidden = YES;
![(下拉刷新04-隐藏状态和时间0)](https://camo.githubusercontent.com/364bc1e09f3b8676d26a73fccdeac4de542c35d3/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230343530383633393533392e676966)
The drop-down refresh 05-DIY title
// Set title
[header setTitle:@"Pull down to refresh" forState:MJRefreshStateIdle];
[header setTitle:@"Release to refresh" forState:MJRefreshStatePulling];
[header setTitle:@"Loading ..." forState:MJRefreshStateRefreshing];
// Set font
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-自定义文字)](https://camo.githubusercontent.com/c30102c6bd5484610365a1d3d3c12681b0ed7a99/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230343536333633333539332e676966)
The drop-down refresh 06-DIY the control of refresh
self.tableView.mj_header = [MJDIYHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// Implementation reference to MJDIYHeader.h和MJDIYHeader.m
![(下拉刷新06-自定义刷新控件)](https://camo.githubusercontent.com/f74e3bd56a693484af7d7e6e300f51c3f8519125/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353031393236313135392e676966)
The pull to refresh 01-Default
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
或
// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData])
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
![(上拉刷新01-默认)](https://camo.githubusercontent.com/3f7d369a043457a3fcb0df2c6e0a2ea36038be61/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353039303034373639362e676966)
The pull to refresh 02-Animation image
// Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData])
MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// Set the refresh image
[footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
// Set footer
self.tableView.mj_footer = footer;
![(上拉刷新02-动画图片)](https://camo.githubusercontent.com/ab905efc2099a577985ba0a1de6f051fdecfde54/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353134313434353739332e676966)
The pull to refresh 03-Hide the title of refresh status
// Hide the title of refresh status
footer.refreshingTitleHidden = YES;
// If does have not above method,then use footer.stateLabel.hidden = YES;
![(上拉刷新03-隐藏刷新状态的文字)](https://camo.githubusercontent.com/4772eed28dc18a8e6509ba794253ab1b41a82ebb/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353230303938353737342e676966)
The pull to refresh 04-All loaded
//Become the status of NoMoreData
[footer noticeNoMoreData];
![(上拉刷新04-全部加载完毕)](https://camo.githubusercontent.com/eb4f2b7ef02210bbaaf1f37152e6c1f6dffd1ab8/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353234383633343638362e676966)
The pull to refresh 05-DIY title
// 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-自定义文字)](https://camo.githubusercontent.com/70889343afd791377f15818115a14403526b4334/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353239353531313135332e676966)
The pull to refresh 06-Hidden After loaded
//Hidden current control of the pull to refresh
self.tableView.mj_footer.hidden = YES;
![(上拉刷新06-加载后隐藏)](https://camo.githubusercontent.com/42a0be4a7bf7676ba476554775fc3bccd617b1c1/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353334333438313832312e676966)
The pull to refresh 07-Automatic back of the pull01
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
![(上拉刷新07-自动回弹的上拉01)](https://camo.githubusercontent.com/2e4c3f3fc477e26f01c4c04328e665036a94d4ad/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353339323233393233312e676966)
The pull to refresh 08-Automatic back of the pull02
MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// Set the normal state of the animated image
[footer setImages:idleImages forState:MJRefreshStateIdle];
// Set the pulling state of animated images(Enter the status of refreshing as soon as loosen)
[footer setImages:pullingImages forState:MJRefreshStatePulling];
// Set the refreshing state of animated images
[footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
// Set footer
self.tableView.mj_footer = footer;
![(上拉刷新07-自动回弹的上拉02)](https://camo.githubusercontent.com/f07cb339c675ff9b5f371856c1c9c07f597c9022/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353434313434333632382e676966)
The pull to refresh 09-DIY the control of refresh(Automatic refresh)
self.tableView.mj_footer = [MJDIYAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// Implementation reference to MJDIYAutoFooter.h和MJDIYAutoFooter.m
![(上拉刷新09-自定义刷新控件(自动刷新))](https://camo.githubusercontent.com/6624420a6f5856c91065d91b3c33e8be43626f8a/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353530303139353836362e676966)
The pull to refresh 10-DIY the control of refresh(Automatic back)
self.tableView.mj_footer = [MJDIYBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// Implementation reference to MJDIYBackFooter.h和MJDIYBackFooter.m
![(上拉刷新10-自定义刷新控件(自动回弹))](https://camo.githubusercontent.com/3bb6216814564a25ce29325ff4ebcf104d500877/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230353536303636363831392e676966)
UICollectionView01-The pull and drop-down refresh
// The drop-down refresh
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
// The pull to refresh
self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
![(UICollectionView01-上下拉刷新)](https://camo.githubusercontent.com/38e09f52d83704da5c00f99c728896260d4aee98/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230363032313630333735382e676966)
UIWebView01-The drop-down refresh
//Add the control of The drop-down refresh
self.webView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//Call this Block When enter the refresh status automatically
}];
![(UICollectionView01-上下拉刷新)](https://camo.githubusercontent.com/97837846aa618b1e05d6c3a523555311f0daa168/687474703a2f2f696d61676573302e636e626c6f67732e636f6d2f626c6f67323031352f3439373237392f3230313530362f3134313230363038303531343532342e676966)
Remind
- ARC
- iOS>=6.0
- iPhone iPad screen anyway