Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. ![(logo)](http://images.cnitblog.com/blog2015/497279/201505/051004492043385.png)
  2. ## MJRefresh
  3. * An easy way to use pull-to-refresh
  4. ## Contents
  5. * Getting Started
  6. * [Features【Support what kinds of controls to refresh】](#Support what kinds of controls to refresh)
  7. * [Installation【How to use MJRefresh】](#How to use MJRefresh)
  8. * [Who's using【More than hundreds of Apps are using MJRefresh】](#>More than hundreds of Apps are using MJRefresh)
  9. * [Classes【The Class Structure Chart of MJRefresh】](#The Class Structure Chart of MJRefresh)
  10. * Comment API
  11. * [MJRefreshComponent.h](#MJRefreshComponent.h)
  12. * [MJRefreshHeader.h](#MJRefreshHeader.h)
  13. * [MJRefreshFooter.h](#MJRefreshFooter.h)
  14. * [MJRefreshAutoFooter.h](#MJRefreshAutoFooter.h)
  15. * Examples
  16. * [Reference](#Reference)
  17. * [The drop-down refresh 01-Default](#The drop-down refresh 01-Default)
  18. * [The drop-down refresh 02-Animation image](#The drop-down refresh 02-Animation image)
  19. * [The drop-down refresh 03-Hide the time](#The drop-down refresh 03-Hide the time)
  20. * [The drop-down refresh 04-Hide status and time](#The drop-down refresh 04-Hide status and time)
  21. * [The drop-down refresh 05-DIY title](#The drop-down refresh 05-DIY title)
  22. * [The drop-down refresh 06-DIY the control of refresh](#The drop-down refresh 06-DIY the control of refresh)
  23. * [The pull to refresh 01-Default](#The pull to refresh 01-Default)
  24. * [The pull to refresh 02-Animation image](#The pull to refresh 02-Animation image)
  25. * [The pull to refresh 03-Hide the title of refresh status](#The pull to refresh 03-Hide the title of refresh status)
  26. * [The pull to refresh 04-All loaded](#The pull to refresh 04-All loaded)
  27. * [The pull to refresh 05-DIY title](#The pull to refresh 05-DIY title)
  28. * [The pull to refresh 06-Hidden After loaded](#The pull to refresh 06-Hidden After loaded)
  29. * [The pull to refresh 07-Automatic back of the pull01](#上The pull to refresh 07-Automatic back of the pull01)
  30. * [The pull to refresh 08-Automatic back of the pull02](#The pull to refresh 08-Automatic back of the pull02)
  31. * [The pull to refresh 09-DIY the control of refresh(Automatic refresh)](#The pull to refresh 09-DIY the control of refresh(Automatic refresh))
  32. * [The pull to refresh 10-DIY the control of refresh(Automatic back)](#The pull to refresh 10-DIY the control of refresh(Automatic back))
  33. * [UICollectionView01-The pull and drop-down refresh](#UICollectionView01-The pull and drop-down refresh)
  34. * [UIWebView01-The drop-down refresh](#UIWebView01-The drop-down refresh)
  35. * [Hope](#Hope)
  36. ## <a id="Support what kinds of controls to refresh"></a>Support what kinds of controls to refresh
  37. * `UIScrollView`、`UITableView`、`UICollectionView`、`UIWebView`
  38. ## <a id="How to use MJRefresh"></a>How to use MJRefresh
  39. * Installation with CocoaPods:`pod 'MJRefresh'`
  40. * Manual import:
  41. * Drag All files in the `MJRefresh` folder to project
  42. * Import the main file:`#import "MJRefresh.h"`
  43. ```objc
  44. Base Custom
  45. MJRefresh.bundle MJRefresh.h
  46. MJRefreshConst.h MJRefreshConst.m
  47. UIScrollView+MJExtension.h UIScrollView+MJExtension.m
  48. UIScrollView+MJRefresh.h UIScrollView+MJRefresh.m
  49. UIView+MJExtension.h UIView+MJExtension.m
  50. ```
  51. ## <a id=">More than hundreds of Apps are using MJRefresh"></a>More than hundreds of Apps are using MJRefresh
  52. <img src="http://images0.cnblogs.com/blog2015/497279/201506/141212365041650.png" width="200" height="300">
  53. * More information of App can focus on:[M了个J-博客园](http://www.cnblogs.com/mjios/p/4409853.html)
  54. ## <a id="The Class Structure Chart of MJRefresh"></a>The Class Structure Chart of MJRefresh
  55. ![](http://images0.cnblogs.com/blog2015/497279/201506/132232456139177.png)
  56. - `The class of red text` in the chart:You can use them directly
  57. - The drop-down refresh control types
  58. - Normal:`MJRefreshNormalHeader`
  59. - Gif:`MJRefreshGifHeader`
  60. - The pull to refresh control types
  61. - Auto refresh
  62. - Normal:`MJRefreshAutoNormalFooter`
  63. - Gif:`MJRefreshAutoGifFooter`
  64. - Auto Back
  65. - Normal:`MJRefreshBackNormalFooter`
  66. - Gif:`MJRefreshBackGifFooter`
  67. - `The class of non-red text` in the chart:For inheritance,to use DIY the control of refresh
  68. - About how to DIY the control of refresh,You can refer the Class in below Chart<br>
  69. <img src="http://images0.cnblogs.com/blog2015/497279/201506/141358159107893.png" width="30%" height="30%">
  70. ## <a id="MJRefreshComponent.h"></a>MJRefreshComponent.h
  71. ```objc
  72. /** The Base Class of refresh control */
  73. @interface MJRefreshComponent : UIView
  74. #pragma mark - Control the state of Refresh
  75. /** BeginRefreshing */
  76. - (void)beginRefreshing;
  77. /** EndRefreshing */
  78. - (void)endRefreshing;
  79. /** IsRefreshing */
  80. - (BOOL)isRefreshing;
  81. #pragma mark - Other
  82. /** According to the drag ratio to change alpha automatically */
  83. @property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;
  84. @end
  85. ```
  86. ## <a id="MJRefreshHeader.h"></a>MJRefreshHeader.h
  87. ```objc
  88. @interface MJRefreshHeader : MJRefreshComponent
  89. /** Creat header */
  90. + (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
  91. /** Creat header */
  92. + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
  93. /** This key is used to storage the time that the last time of drown-down successfully */
  94. @property (copy, nonatomic) NSString *lastUpdatedTimeKey;
  95. /** The last time of drown-down successfully */
  96. @property (strong, nonatomic, readonly) NSDate *lastUpdatedTime;
  97. /** Ignored scrollView contentInset top */
  98. @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop;
  99. @end
  100. ```
  101. ## <a id="MJRefreshFooter.h"></a>MJRefreshFooter.h
  102. ```objc
  103. @interface MJRefreshFooter : MJRefreshComponent
  104. /** Creat footer */
  105. + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
  106. /** Creat footer */
  107. + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
  108. /** NoticeNoMoreData */
  109. - (void)noticeNoMoreData;
  110. /** ResetNoMoreData(Clear the status of NoMoreData ) */
  111. - (void)resetNoMoreData;
  112. /** Ignored scrollView contentInset bottom */
  113. @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom;
  114. /** Automaticlly show or hidden by the count of data(Show-have data,Hidden- no data) */
  115. @property (assign, nonatomic) BOOL automaticallyHidden;
  116. @end
  117. ```
  118. ## <a id="MJRefreshAutoFooter.h"></a>MJRefreshAutoFooter.h
  119. ```objc
  120. @interface MJRefreshAutoFooter : MJRefreshFooter
  121. /** Is Automatically Refresh(Default is Yes) */
  122. @property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh;
  123. /** 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) */
  124. @property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent;
  125. @end
  126. ```
  127. ## <a id="Reference"></a>Reference
  128. ```objc
  129. * Due to there are more functions of this framework,Don't write specific text describe its usage
  130. * You can directly reference examples MJTableViewController、MJCollectionViewController、MJWebViewController,More intuitive and fast.
  131. ```
  132. <img src="http://images0.cnblogs.com/blog2015/497279/201506/141345470048120.png" width="30%" height="30%">
  133. ## <a id="The drop-down refresh 01-Default"></a>The drop-down refresh 01-Default
  134. ```objc
  135. self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  136. //Call this Block When enter the refresh status automatically
  137. }];
  138. // Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadNewData])
  139. self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
  140. // Enter the refresh status immediately
  141. [self.tableView.header beginRefreshing];
  142. ```
  143. ![(下拉刷新01-普通)](http://images0.cnblogs.com/blog2015/497279/201506/141204343486151.gif)
  144. ## <a id="The drop-down refresh 02-Animation image"></a>The drop-down refresh 02-Animation image
  145. ```objc
  146. // Set the callback(一Once you enter the refresh status,then call the action of target,that is call [self loadNewData])
  147. MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
  148. // Set the ordinary state of animated images
  149. [header setImages:idleImages forState:MJRefreshStateIdle];
  150. // Set the pulling state of animated images(Enter the status of refreshing as soon as loosen)
  151. [header setImages:pullingImages forState:MJRefreshStatePulling];
  152. // Set the refreshing state of animated images
  153. [header setImages:refreshingImages forState:MJRefreshStateRefreshing];
  154. // Set header
  155. self.tableView.mj_header = header;
  156. ```
  157. ![(下拉刷新02-动画图片)](http://images0.cnblogs.com/blog2015/497279/201506/141204402238389.gif)
  158. ## <a id="The drop-down refresh 03-Hide the time"></a>The drop-down refresh 03-Hide the time
  159. ```objc
  160. // Hide the time
  161. header.lastUpdatedTimeLabel.hidden = YES;
  162. ```
  163. ![(下拉刷新03-隐藏时间)](http://images0.cnblogs.com/blog2015/497279/201506/141204456132944.gif)
  164. ## <a id="The drop-down refresh 04-Hide status and time"></a>The drop-down refresh 04-Hide status and time
  165. ```objc
  166. // Hide the time
  167. header.lastUpdatedTimeLabel.hidden = YES;
  168. // Hide the status
  169. header.stateLabel.hidden = YES;
  170. ```
  171. ![(下拉刷新04-隐藏状态和时间0)](http://images0.cnblogs.com/blog2015/497279/201506/141204508639539.gif)
  172. ## <a id="The drop-down refresh 05-DIY title"></a>The drop-down refresh 05-DIY title
  173. ```objc
  174. // Set title
  175. [header setTitle:@"Pull down to refresh" forState:MJRefreshStateIdle];
  176. [header setTitle:@"Release to refresh" forState:MJRefreshStatePulling];
  177. [header setTitle:@"Loading ..." forState:MJRefreshStateRefreshing];
  178. // Set font
  179. header.stateLabel.font = [UIFont systemFontOfSize:15];
  180. header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];
  181. // Set textColor
  182. header.stateLabel.textColor = [UIColor redColor];
  183. header.lastUpdatedTimeLabel.textColor = [UIColor blueColor];
  184. ```
  185. ![(下拉刷新05-自定义文字)](http://images0.cnblogs.com/blog2015/497279/201506/141204563633593.gif)
  186. ## <a id="The drop-down refresh 06-DIY the control of refresh"></a>The drop-down refresh 06-DIY the control of refresh
  187. ```objc
  188. self.tableView.mj_header = [MJDIYHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
  189. // Implementation reference to MJDIYHeader.h和MJDIYHeader.m
  190. ```
  191. ![(下拉刷新06-自定义刷新控件)](http://images0.cnblogs.com/blog2015/497279/201506/141205019261159.gif)
  192. ## <a id="The pull to refresh 01-Default"></a>The pull to refresh 01-Default
  193. ```objc
  194. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  195. //Call this Block When enter the refresh status automatically
  196. }];
  197. // Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData])
  198. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  199. ```
  200. ![(上拉刷新01-默认)](http://images0.cnblogs.com/blog2015/497279/201506/141205090047696.gif)
  201. ## <a id="The pull to refresh 02-Animation image"></a>The pull to refresh 02-Animation image
  202. ```objc
  203. // Set the callback(Once you enter the refresh status,then call the action of target,that is call [self loadMoreData])
  204. MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  205. // Set the refresh image
  206. [footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
  207. // Set footer
  208. self.tableView.mj_footer = footer;
  209. ```
  210. ![(上拉刷新02-动画图片)](http://images0.cnblogs.com/blog2015/497279/201506/141205141445793.gif)
  211. ## <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
  212. ```objc
  213. // Hide the title of refresh status
  214. footer.refreshingTitleHidden = YES;
  215. // If does have not above method,then use footer.stateLabel.hidden = YES;
  216. ```
  217. ![(上拉刷新03-隐藏刷新状态的文字)](http://images0.cnblogs.com/blog2015/497279/201506/141205200985774.gif)
  218. ## <a id="The pull to refresh 04-All loaded"></a>The pull to refresh 04-All loaded
  219. ```objc
  220. //Become the status of NoMoreData
  221. [footer noticeNoMoreData];
  222. ```
  223. ![(上拉刷新04-全部加载完毕)](http://images0.cnblogs.com/blog2015/497279/201506/141205248634686.gif)
  224. ## <a id="The pull to refresh 05-DIY title"></a>The pull to refresh 05-DIY title
  225. ```objc
  226. // Set title
  227. [footer setTitle:@"Click or drag up to refresh" forState:MJRefreshStateIdle];
  228. [footer setTitle:@"Loading more ..." forState:MJRefreshStateRefreshing];
  229. [footer setTitle:@"No more data" forState:MJRefreshStateNoMoreData];
  230. // Set font
  231. footer.stateLabel.font = [UIFont systemFontOfSize:17];
  232. // Set textColor
  233. footer.stateLabel.textColor = [UIColor blueColor];
  234. ```
  235. ![(上拉刷新05-自定义文字)](http://images0.cnblogs.com/blog2015/497279/201506/141205295511153.gif)
  236. ## <a id="The pull to refresh 06-Hidden After loaded"></a>The pull to refresh 06-Hidden After loaded
  237. ```objc
  238. //Hidden current control of the pull to refresh
  239. self.tableView.mj_footer.hidden = YES;
  240. ```
  241. ![(上拉刷新06-加载后隐藏)](http://images0.cnblogs.com/blog2015/497279/201506/141205343481821.gif)
  242. ## <a id="The pull to refresh 07-Automatic back of the pull01"></a>The pull to refresh 07-Automatic back of the pull01
  243. ```objc
  244. self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  245. ```
  246. ![(上拉刷新07-自动回弹的上拉01)](http://images0.cnblogs.com/blog2015/497279/201506/141205392239231.gif)
  247. ## <a id="The pull to refresh 08-Automatic back of the pull02"></a>The pull to refresh 08-Automatic back of the pull02
  248. ```objc
  249. MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  250. // Set the normal state of the animated image
  251. [footer setImages:idleImages forState:MJRefreshStateIdle];
  252. // Set the pulling state of animated images(Enter the status of refreshing as soon as loosen)
  253. [footer setImages:pullingImages forState:MJRefreshStatePulling];
  254. // Set the refreshing state of animated images
  255. [footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
  256. // Set footer
  257. self.tableView.mj_footer = footer;
  258. ```
  259. ![(上拉刷新07-自动回弹的上拉02)](http://images0.cnblogs.com/blog2015/497279/201506/141205441443628.gif)
  260. ## <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)
  261. ```objc
  262. self.tableView.mj_footer = [MJDIYAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  263. // Implementation reference to MJDIYAutoFooter.h和MJDIYAutoFooter.m
  264. ```
  265. ![(上拉刷新09-自定义刷新控件(自动刷新))](http://images0.cnblogs.com/blog2015/497279/201506/141205500195866.gif)
  266. ## <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)
  267. ```objc
  268. self.tableView.mj_footer = [MJDIYBackFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
  269. // Implementation reference to MJDIYBackFooter.h和MJDIYBackFooter.m
  270. ```
  271. ![(上拉刷新10-自定义刷新控件(自动回弹))](http://images0.cnblogs.com/blog2015/497279/201506/141205560666819.gif)
  272. ## <a id="UICollectionView01-The pull and drop-down refresh"></a>UICollectionView01-The pull and drop-down refresh
  273. ```objc
  274. // The drop-down refresh
  275. self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  276. //Call this Block When enter the refresh status automatically
  277. }];
  278. // The pull to refresh
  279. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  280. //Call this Block When enter the refresh status automatically
  281. }];
  282. ```
  283. ![(UICollectionView01-上下拉刷新)](http://images0.cnblogs.com/blog2015/497279/201506/141206021603758.gif)
  284. ## <a id="UIWebView01-The drop-down refresh"></a>UIWebView01-The drop-down refresh
  285. ```objc
  286. //Add the control of The drop-down refresh
  287. self.webView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  288. //Call this Block When enter the refresh status automatically
  289. }];
  290. ```
  291. ![(UICollectionView01-上下拉刷新)](http://images0.cnblogs.com/blog2015/497279/201506/141206080514524.gif)
  292. ## Remind
  293. * ARC
  294. * iOS>=6.0
  295. * iPhone \ iPad screen anyway
  296. ## <a id="Hope"></a>Hope
  297. * If you find bug when used,Hope you can Issues me,Thank you or try to download the latest code of this framework to see the BUG has been fixed or not)
  298. * If you find the function is not enough when used,Hope you can Issues me,I very much to add more useful function to this framework ,Thank you !
  299. * If you want to contribute code for MJRefresh,please Pull Requests me
  300. * If you use MJRefresh in your develop app,Hope you can go to[CocoaControls](https://www.cocoacontrols.com/controls/mjrefresh)to add the iTunes path
  301. of you app,I Will install your app,and according to the usage of many app,to be a better design and improve to MJRefresh,Thank you !
  302. * StepO1(WeChat is just an Example,Explore“Your app name itunes”)
  303. ![(step01)](http://ww4.sinaimg.cn/mw1024/800cdf9ctw1eq0viiv5rsj20sm0ea41t.jpg)
  304. * StepO2
  305. ![(step02)](http://ww2.sinaimg.cn/mw1024/800cdf9ctw1eq0vilejxlj20tu0me7a0.jpg)
  306. * StepO3
  307. ![(step03)](http://ww1.sinaimg.cn/mw1024/800cdf9ctw1eq0viocpo5j20wc0dc0un.jpg)
  308. * StepO4
  309. ![(step04)](http://ww3.sinaimg.cn/mw1024/800cdf9ctw1eq0vir137xj20si0gewgu.jpg)