项目作者: CoderMJLee

项目描述 :
使用pull-to-refresh的简单方法。
高级语言: Objective-C
项目地址: git://github.com/CoderMJLee/MJRefresh.git
创建时间: 2014-05-23T16:22:32Z
项目社区:https://github.com/CoderMJLee/MJRefresh

开源协议:MIT License

下载


MJRefresh

SPM supported
Carthage compatible
podversion

  • An easy way to use pull-to-refresh

📜✍🏻Release Notes: more details

Contents

New Features

Support Flips In CollectionViewLayout" class="reference-link">Support Flips In CollectionViewLayout

Refer to issue #1616.

  • Use additionalFlipsViews to append views that need to flip when collectionViewLayout flipsHorizontallyInOppositeLayoutDirection is true.
  • Use flipsHorizontallyInOppositeLayoutDirectionViews to modify views as the same way above. ⚠️ BUT parent class may be affected. Use additionalFlipsViews instead.

Dynamic i18n Switching" class="reference-link">Dynamic i18n Switching

Now MJRefresh components will be rerendered automatically with MJRefreshConfig.default.language setting.

Example

Go i18n folder and see lots of cases. Simulator example is behind i18n tab in right-top corner.

Setting language

  1. MJRefreshConfig.default.language = "zh-hans"

Setting i18n file name

  1. MJRefreshConfig.default.i18nFilename = "i18n File Name(not include type<.strings>)"

Setting i18n language bundle

  1. MJRefreshConfig.default.i18nBundle = <i18n Bundle>

Adopting the feature in your DIY component

  1. Just override i18nDidChange function and reset texts.
  1. // must use this localization methods
  2. Bundle.mj_localizedString(forKey: "")
  3. // or
  4. Bundle.mj_localizedString(forKey: "", value:"")
  5. override func i18nDidChange() {
  6. // Reset texts function
  7. setupTexts()
  8. // Make sure to call super after resetting texts. It will call placeSubViews for applying new layout.
  9. super.i18nDidChange()
  10. }
  1. Receiving MJRefreshDidChangeLanguageNotification notification.

SPM Supported" class="reference-link">SPM Supported

Released from 3.7.1

Swift Chaining Grammar Supported" class="reference-link">Swift Chaining Grammar Supported

  1. // Example as MJRefreshNormalHeader
  2. func addRefreshHeader() {
  3. MJRefreshNormalHeader { [weak self] in
  4. // load some data
  5. }.autoChangeTransparency(true)
  6. .link(to: tableView)
  7. }

Support what kinds of controls to refresh" class="reference-link">Support what kinds of controls to refresh

  • UIScrollViewUITableViewUICollectionViewWKWebView

How to use MJRefresh" class="reference-link">How to use MJRefresh

  • Installation with CocoaPods:pod 'MJRefresh'
  • Installation with Carthagegithub "CoderMJLee/MJRefresh"
  • Manual import:
    • Drag All files in the MJRefresh folder to project
    • Import the main file:#import "MJRefresh.h"
  1. Base Custom
  2. MJRefresh.bundle MJRefresh.h
  3. MJRefreshConst.h MJRefreshConst.m
  4. UIScrollView+MJExtension.h UIScrollView+MJExtension.m
  5. UIScrollView+MJRefresh.h UIScrollView+MJRefresh.m
  6. UIView+MJExtension.h UIView+MJExtension.m

More than hundreds of Apps are using MJRefresh" class="reference-link">More than hundreds of Apps are using MJRefresh

The Class Structure Chart of MJRefresh" class="reference-link">The Class Structure Chart of MJRefresh

  • 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

MJRefreshComponent.h" class="reference-link">MJRefreshComponent.h

  1. /** The Base Class of refresh control */
  2. @interface MJRefreshComponent : UIView
  3. #pragma mark - Control the state of Refresh
  4. /** BeginRefreshing */
  5. - (void)beginRefreshing;
  6. /** EndRefreshing */
  7. - (void)endRefreshing;
  8. /** IsRefreshing */
  9. - (BOOL)isRefreshing;
  10. #pragma mark - Other
  11. /** According to the drag ratio to change alpha automatically */
  12. @property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;
  13. @end

MJRefreshHeader.h" class="reference-link">MJRefreshHeader.h

  1. @interface MJRefreshHeader : MJRefreshComponent
  2. /** create header */
  3. + (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
  4. /** create header */
  5. + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
  6. /** This key is used to storage the time that the last time of drown-down successfully */
  7. @property (copy, nonatomic) NSString *lastUpdatedTimeKey;
  8. /** The last time of drown-down successfully */
  9. @property (strong, nonatomic, readonly) NSDate *lastUpdatedTime;
  10. /** Ignored scrollView contentInset top */
  11. @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop;
  12. @end

MJRefreshFooter.h" class="reference-link">MJRefreshFooter.h

  1. @interface MJRefreshFooter : MJRefreshComponent
  2. /** create footer */
  3. + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
  4. /** create footer */
  5. + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
  6. /** NoticeNoMoreData */
  7. - (void)noticeNoMoreData;
  8. /** ResetNoMoreData(Clear the status of NoMoreData ) */
  9. - (void)resetNoMoreData;
  10. /** Ignored scrollView contentInset bottom */
  11. @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom;
  12. @end

MJRefreshAutoFooter.h" class="reference-link">MJRefreshAutoFooter.h

  1. @interface MJRefreshAutoFooter : MJRefreshFooter
  2. /** Is Automatically Refresh(Default is Yes) */
  3. @property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh;
  4. /** 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) */
  5. @property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent;
  6. @end

MJRefreshTrailer.h" class="reference-link"> MJRefreshTrailer.h

  1. @interface MJRefreshTrailer : MJRefreshComponent
  2. /** 创建trailer */
  3. + (instancetype)trailerWithRefreshingBlock:(MJRefreshComponentAction)refreshingBlock;
  4. /** 创建trailer */
  5. + (instancetype)trailerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
  6. /** 忽略多少scrollView的contentInset的right */
  7. @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetRight;
  8. @end

Reference" class="reference-link">Reference

  1. * Due to there are more functions of this frameworkDon't write specific text describe its usage
  2. * You can directly reference examples MJTableViewController、MJCollectionViewController、MJWebViewController,More intuitive and fast.

The drop-down refresh 01-Default" class="reference-link">The drop-down refresh 01-Default

  1. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  2. //Call this Block When enter the refresh status automatically
  3. }];
  4. // Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadNewData])
  5. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
  6. // Enter the refresh status immediately
  7. [self.tableView.mj_header beginRefreshing];

(下拉刷新01-普通)

The drop-down refresh 02-Animation image" class="reference-link">The drop-down refresh 02-Animation image

  1. // Set the callback(一Once you enter the refresh status,then call the action of target,that is call [self loadNewData])
  2. MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
  3. // Set the ordinary state of animated images
  4. [header setImages:idleImages forState:MJRefreshStateIdle];
  5. // Set the pulling state of animated images(Enter the status of refreshing as soon as loosen)
  6. [header setImages:pullingImages forState:MJRefreshStatePulling];
  7. // Set the refreshing state of animated images
  8. [header setImages:refreshingImages forState:MJRefreshStateRefreshing];
  9. // Set header
  10. self.tableView.mj_header = header;

(下拉刷新02-动画图片)

The drop-down refresh 03-Hide the time" class="reference-link">The drop-down refresh 03-Hide the time

  1. // Hide the time
  2. header.lastUpdatedTimeLabel.hidden = YES;

(下拉刷新03-隐藏时间)

The drop-down refresh 04-Hide status and time" class="reference-link">The drop-down refresh 04-Hide status and time

  1. // Hide the time
  2. header.lastUpdatedTimeLabel.hidden = YES;
  3. // Hide the status
  4. header.stateLabel.hidden = YES;

(下拉刷新04-隐藏状态和时间0)

The drop-down refresh 05-DIY title" class="reference-link">The drop-down refresh 05-DIY title

  1. // Set title
  2. [header setTitle:@"Pull down to refresh" forState:MJRefreshStateIdle];
  3. [header setTitle:@"Release to refresh" forState:MJRefreshStatePulling];
  4. [header setTitle:@"Loading ..." forState:MJRefreshStateRefreshing];
  5. // Set font
  6. header.stateLabel.font = [UIFont systemFontOfSize:15];
  7. header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];
  8. // Set textColor
  9. header.stateLabel.textColor = [UIColor redColor];
  10. header.lastUpdatedTimeLabel.textColor = [UIColor blueColor];

(下拉刷新05-自定义文字)

The drop-down refresh 06-DIY the control of refresh" class="reference-link">The drop-down refresh 06-DIY the control of refresh

  1. self.tableView.mj_header = [MJDIYHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
  2. // Implementation reference to MJDIYHeader.h和MJDIYHeader.m

(下拉刷新06-自定义刷新控件)

The pull to refresh 01-Default" class="reference-link">The pull to refresh 01-Default

  1. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  2. //Call this Block When enter the refresh status automatically
  3. }];
  4. // Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData])
  5. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];

(上拉刷新01-默认)

The pull to refresh 02-Animation image" class="reference-link">The pull to refresh 02-Animation image

  1. // Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData])
  2. MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  3. // Set the refresh image
  4. [footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
  5. // Set footer
  6. self.tableView.mj_footer = footer;

(上拉刷新02-动画图片)

The pull to refresh 03-Hide the title of refresh status" class="reference-link">The pull to refresh 03-Hide the title of refresh status

  1. // Hide the title of refresh status
  2. footer.refreshingTitleHidden = YES;
  3. // If does have not above method,then use footer.stateLabel.hidden = YES;

(上拉刷新03-隐藏刷新状态的文字)

The pull to refresh 04-All loaded" class="reference-link">The pull to refresh 04-All loaded

  1. //Become the status of NoMoreData
  2. [footer noticeNoMoreData];

(上拉刷新04-全部加载完毕)

The pull to refresh 05-DIY title" class="reference-link">The pull to refresh 05-DIY title

  1. // Set title
  2. [footer setTitle:@"Click or drag up to refresh" forState:MJRefreshStateIdle];
  3. [footer setTitle:@"Loading more ..." forState:MJRefreshStateRefreshing];
  4. [footer setTitle:@"No more data" forState:MJRefreshStateNoMoreData];
  5. // Set font
  6. footer.stateLabel.font = [UIFont systemFontOfSize:17];
  7. // Set textColor
  8. footer.stateLabel.textColor = [UIColor blueColor];

(上拉刷新05-自定义文字)

The pull to refresh 06-Hidden After loaded" class="reference-link">The pull to refresh 06-Hidden After loaded

  1. //Hidden current control of the pull to refresh
  2. self.tableView.mj_footer.hidden = YES;

(上拉刷新06-加载后隐藏)

The pull to refresh 07-Automatic back of the pull01" class="reference-link">The pull to refresh 07-Automatic back of the pull01

  1. self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];

(上拉刷新07-自动回弹的上拉01)

The pull to refresh 08-Automatic back of the pull02" class="reference-link">The pull to refresh 08-Automatic back of the pull02

  1. MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  2. // Set the normal state of the animated image
  3. [footer setImages:idleImages forState:MJRefreshStateIdle];
  4. // Set the pulling state of animated images(Enter the status of refreshing as soon as loosen)
  5. [footer setImages:pullingImages forState:MJRefreshStatePulling];
  6. // Set the refreshing state of animated images
  7. [footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
  8. // Set footer
  9. self.tableView.mj_footer = footer;

(上拉刷新07-自动回弹的上拉02)

The pull to refresh 09-DIY the control of refresh(Automatic refresh)" class="reference-link">The pull to refresh 09-DIY the control of refresh(Automatic refresh)

  1. self.tableView.mj_footer = [MJDIYAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  2. // Implementation reference to MJDIYAutoFooter.h和MJDIYAutoFooter.m

(上拉刷新09-自定义刷新控件(自动刷新))

The pull to refresh 10-DIY the control of refresh(Automatic back)" class="reference-link">The pull to refresh 10-DIY the control of refresh(Automatic back)

  1. self.tableView.mj_footer = [MJDIYBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  2. // Implementation reference to MJDIYBackFooter.h和MJDIYBackFooter.m

(上拉刷新10-自定义刷新控件(自动回弹))

UICollectionView01-The pull and drop-down refresh" class="reference-link">UICollectionView01-The pull and drop-down refresh

  1. // The drop-down refresh
  2. self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  3. //Call this Block When enter the refresh status automatically
  4. }];
  5. // The pull to refresh
  6. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  7. //Call this Block When enter the refresh status automatically
  8. }];

(UICollectionView01-上下拉刷新)

UICollectionView02-The trailer refresh" class="reference-link">UICollectionView02-The trailer refresh

  1. // The trailer refresh
  2. self.collectionView.mj_trailer = [MJRefreshNormalTrailer trailerWithRefreshingBlock:^{
  3. //Call this Block When enter the refresh status automatically
  4. }];

(UICollectionView02-左拉刷新)

WKWebView01-The drop-down refresh" class="reference-link">WKWebView01-The drop-down refresh

  1. //Add the control of The drop-down refresh
  2. self.webView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  3. //Call this Block When enter the refresh status automatically
  4. }];

(UICollectionView01-上下拉刷新)

Remind

  • ARC
  • iOS>=9.0
  • iPhone \ iPad screen anyway

寻求志同道合的小伙伴

  • 因本人工作忙,没有太多时间去维护MJRefresh,在此向广大框架使用者说声:非常抱歉!😞
  • 现寻求志同道合的小伙伴一起维护此框架,有兴趣的小伙伴可以发邮件给我,非常感谢😊
  • 如果一切OK,我将开放框架维护权限(github、pod等)
  • 目前已经找到3位小伙伴(^-^)V