12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- // UIScrollView+Refresh.m
- // homy
- //
- // Created by 翟玉磊 on 2018/11/9.
- // Copyright © 2018 翟玉磊. All rights reserved.
- //
- #import "UIScrollView+Refresh.h"
- #import "BaseRefreshHeader.h"
- #import "BaseRefreshFooter.h"
- #import "BaseRefreshAutoNormalFooter.h"
- #import "BaseLottieRefreshHeader.h"
- @implementation UIScrollView (Refresh)
- /// 添加下拉刷新控件
- - (MJRefreshHeader *)addHeaderRefresh:(void(^)(MJRefreshHeader *header))refreshingBlock {
-
- __weak typeof(&*self) weakSelf = self;
- BaseLottieRefreshHeader *mj_header = [BaseLottieRefreshHeader headerWithRefreshingBlock:^{
- __strong typeof(&*weakSelf) strongSelf = weakSelf;
- !refreshingBlock?:refreshingBlock((MJRefreshNormalHeader *)strongSelf.mj_header);
- }];
- // 设置自动切换透明度(在导航栏下面自动隐藏)
- mj_header.automaticallyChangeAlpha = YES;
- // Configure normal mj_header
- self.mj_header = mj_header;
- return mj_header;
- }
- /// 添加上拉加载控件
- - (MJRefreshFooter *)addFooterRefresh:(void(^)(MJRefreshFooter *footer))refreshingBlock {
- __weak typeof(&*self) weakSelf = self;
- BaseRefreshFooter *mj_footer = [BaseRefreshFooter footerWithRefreshingBlock:^{
- __strong typeof(&*weakSelf) strongSelf = weakSelf;
- !refreshingBlock?:refreshingBlock((MJRefreshAutoNormalFooter *)strongSelf.mj_footer);
- }];
- self.mj_footer = mj_footer;
- return mj_footer;
- }
- /// 添加下拉刷新控件
- - (MJRefreshHeader *)addImageHeaderRefresh:(void(^)(MJRefreshHeader *header))refreshingBlock {
- __weak typeof(&*self) weakSelf = self;
- BaseRefreshHeader *mj_header = [BaseRefreshHeader headerWithRefreshingBlock:^{
- __strong typeof(&*weakSelf) strongSelf = weakSelf;
- !refreshingBlock?:refreshingBlock((MJRefreshNormalHeader *)strongSelf.mj_header);
- }];
- // 设置自动切换透明度(在导航栏下面自动隐藏)
- mj_header.automaticallyChangeAlpha = YES;
- // Configure normal mj_header
- self.mj_header = mj_header;
- return mj_header;
- }
- /// 添加上拉加载控件
- - (MJRefreshFooter *)addImageFooterRefresh:(void(^)(MJRefreshFooter *footer))refreshingBlock {
- __weak typeof(&*self) weakSelf = self;
- BaseRefreshFooter *mj_footer = [BaseRefreshFooter footerWithRefreshingBlock:^{
- __strong typeof(&*weakSelf) strongSelf = weakSelf;
- !refreshingBlock?:refreshingBlock((MJRefreshAutoNormalFooter *)strongSelf.mj_footer);
- }];
- self.mj_footer = mj_footer;
- return mj_footer;
- }
- /// 添加下拉刷新控件
- - (MJRefreshNormalHeader *)native_addHeaderRefresh:(void(^)(MJRefreshNormalHeader *header))refreshingBlock {
-
- __weak __typeof(&*self) weakSelf = self;
- MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- __weak __typeof(&*weakSelf) strongSelf = weakSelf;
- !refreshingBlock?:refreshingBlock((MJRefreshNormalHeader *)strongSelf.mj_header);
- }];
- mj_header.lastUpdatedTimeLabel.hidden = YES;
- // Configure normal mj_header
- self.mj_header = mj_header;
- return mj_header;
- }
- /// 添加上拉加载控件
- - (BaseRefreshAutoNormalFooter *)native_addFooterRefresh:(void(^)(MJRefreshAutoNormalFooter *footer))refreshingBlock {
- __weak __typeof(&*self) weakSelf = self;
- BaseRefreshAutoNormalFooter *mj_footer = [BaseRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- __weak __typeof(&*weakSelf) strongSelf = weakSelf;
- !refreshingBlock?:refreshingBlock((BaseRefreshAutoNormalFooter *)strongSelf.mj_footer);
- }];
- // Configure normal mj_footer
- [mj_footer setTitle:@"~ 持续更新中 ~" forState:MJRefreshStateNoMoreData];
- [mj_footer setTitleColor:Color(204, 204, 204) forState:MJRefreshStateNoMoreData];
- self.mj_footer = mj_footer;
- return mj_footer;
- }
- @end
|