Contents

CoderMJLee/MJRefresh

An easy way to use pull-to-refresh.

MJRefresh

[[SPM supported]](https://github.com/apple/swift-package-manager) [[Carthage compatible]](https://github.com/Carthage/Carthage) [[podversion]](https://cocoapods.org/pods/MJRefresh)

  • An easy way to use pull-to-refresh

📜✍🏻Release Notes: more details

Contents

  • New Features

- Support Flips in CollectionViewLayout - Dynamic i18n Switching - SPM Supported - Swift Chaining Grammar Supported

  • Getting Started

Features【Support what kinds of controls to refresh】 Installation【How to use MJRefresh】 Who's using【More than hundreds of Apps are using MJRefresh】 Classes【The Class Structure Chart of MJRefresh】

  • Comment API

MJRefreshComponent.h MJRefreshHeader.h MJRefreshFooter.h MJRefreshAutoFooter.h * MJRefreshTrailer.h

  • Examples

Reference The drop-down refresh 01-Default The drop-down refresh 02-Animation image The drop-down refresh 03-Hide the time The drop-down refresh 04-Hide status and time The drop-down refresh 05-DIY title The drop-down refresh 06-DIY the control of refresh The pull to refresh 01-Default The pull to refresh 02-Animation image The pull to refresh 03-Hide the title of refresh status The pull to refresh 04-All loaded The pull to refresh 05-DIY title The pull to refresh 06-Hidden After loaded The pull to refresh 07-Automatic back of the pull01 The pull to refresh 08-Automatic back of the pull02 The pull to refresh 09-DIY the control of refresh(Automatic refresh)) The pull to refresh 10-DIY the control of refresh(Automatic back)) UICollectionView01-The pull and drop-down refresh UICollectionView02-The trailer refresh WKWebView01-The drop-down refresh

New Features

<a id="SupportFlipsInCollectionViewLayout"></a>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.

<a id="dynamic_i18n_switching"></a>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
MJRefreshConfig.default.language = "zh-hans"
Setting i18n file name
MJRefreshConfig.default.i18nFilename = "i18n File Name(not include type<.strings>)"
Setting i18n language bundle
MJRefreshConfig.default.i18nBundle = <i18n Bundle>
Adopting the feature in your DIY component
  1. Just override i18nDidChange function and reset texts.
// must use this localization methods
Bundle.mj_localizedString(forKey: "")
// or
Bundle.mj_localizedString(forKey: "", value:"")

override func i18nDidChange() {
    // Reset texts function
    setupTexts()
    // Make sure to call super after resetting texts. It will call placeSubViews for applying new layout.
    super.i18nDidChange()
}
  1. Receiving MJRefreshDidChangeLanguageNotification notification.

<a id="spm_supported"></a>SPM Supported

Released from 3.7.1

<a id="swift_chaining_grammar_supported"></a>Swift Chaining Grammar Supported

  // Example as MJRefreshNormalHeader
  func addRefreshHeader() {
      MJRefreshNormalHeader { [weak self] in
  	  // load some data
      }.autoChangeTransparency(true)
      .link(to: tableView)
  }

<a id="Support_what_kinds_of_controls_to_refresh"></a>Support what kinds of controls to refresh

  • UIScrollViewUITableViewUICollectionViewWKWebView

<a id="How_to_use_MJRefresh"></a>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"

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

<a id="More_than_hundreds_of_Apps_are_using_MJRefresh"></a>More than hundreds of Apps are using MJRefresh

<img src="http://images0.cnblogs.com/blog2015/497279/201506/141212365041650.png" width="200" height="300">

<a id="The_Class_Structure_Chart_of_MJRefresh"></a>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<br>

<img src="http://images0.cnblogs.com/blog2015/497279/201506/141358159107893.png" width="30%" height="30%">

<a id="MJRefreshComponent.h"></a>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

<a id="MJRefreshHeader.h"></a>MJRefreshHeader.h

@interface MJRefreshHeader : MJRefreshComponent
/** create header */
+ (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
/** create 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

<a id="MJRefreshFooter.h"></a>MJRefreshFooter.h

@interface MJRefreshFooter : MJRefreshComponent
/** create footer */
+ (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
/** create 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;
@end

<a id="MJRefreshAutoFooter.h"></a>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

<a id="MJRefreshTrailer.h"></a> MJRefreshTrailer.h

@interface MJRefreshTrailer : MJRefreshComponent

/** 创建trailer */
+ (instancetype)trailerWithRefreshingBlock:(MJRefreshComponentAction)refreshingBlock;
/** 创建trailer */
+ (instancetype)trailerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;

/** 忽略多少scrollView的contentInset的right */
@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetRight;

@end

<a id="Reference"></a>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.

<img src="http://images0.cnblogs.com/blog2015/497279/201506/141345470048120.png" width="30%" height="30%">

<a id="The_drop-down_refresh_01-Default"></a>The drop-down refresh 01-Default

self.tableView.mj_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.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];

// Enter the refresh status immediately
[self.tableView.mj_header beginRefreshing];

[(下拉刷新01-普通)]

<a id="The_drop-down_refresh_02-Animation_image"></a>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-动画图片)]

<a id="The_drop-down_refresh_03-Hide_the_time"></a>The drop-down refresh 03-Hide the time

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

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

<a id="The_drop-down_refresh_04-Hide_status_and_time"></a>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)]

<a id="The_drop-down_refresh_05-DIY_title"></a>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-自定义文字)]

<a id="The_drop-down_refresh_06-DIY_the_control_of_refresh"></a>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-自定义刷新控件)]

<a id="The_pull_to_refresh_01-Default"></a>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-默认)]

<a id="The_pull_to_refresh_02-Animation_image"></a>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-动画图片)]

<a id="The_pull_to_refresh_03-Hide_the_title_of_refresh_status"></a>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-隐藏刷新状态的文字)]

<a id="The_pull_to_refresh_04-All_loaded"></a>The pull to refresh 04-All loaded

//Become the status of NoMoreData
[footer noticeNoMoreData];

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

<a id="The_pull_to_refresh_05-DIY_title"></a>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-自定义文字)]

<a id="The_pull_to_refresh_06-Hidden_After_loaded"></a>The pull to refresh 06-Hidden After loaded

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

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

<a id="The_pull_to_refresh_07-Automatic_back_of_the_pull01"></a>The pull to refresh 07-Automatic back of the pull01

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

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

<a id="The_pull_to_refresh_08-Automatic_back_of_the_pull02"></a>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)]

<a id="The_pull_to_refresh_09-DIY_the_control_of_refresh(Automatic_refresh)"></a>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-自定义刷新控件(自动刷新))]

<a id="The_pull_to_refresh_10-DIY_the_control_of_refresh(Automatic_back)"></a>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-自定义刷新控件(自动回弹))]

<a id="UICollectionView01-The_pull_and_drop-down_refresh"></a>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-上下拉刷新)]

<a id="UICollectionView02-The_trailer_refresh"></a>UICollectionView02-The trailer refresh

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

[(UICollectionView02-左拉刷新)]

<a id="WKWebView01-The_drop-down_refresh"></a>WKWebView01-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-上下拉刷新)]

Remind

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

寻求志同道合的小伙伴

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

Package Metadata

Repository: CoderMJLee/MJRefresh

Stars: 13825

Forks: 3530

Open issues: 59

Default branch: master

Primary language: objective-c

License: MIT

Topics: objective-c, refresh

README: README.md