支持的控件
UITableView,UICollectionView,UIScrollView,UIWebView
下拉刷新
- Normal : MJRefreshNormalHeader
- Gif : MJRefreshGifHeader
上拉加载
- Normal : MJRefreshBackNormalFooter / MJRefreshAutoNormalFooter
- Gif : MJRefreshBackGifFooter / MJRefreshAutoGifFooter
使用时有Block 和 Target-Action两种模式
基础使用
//防止循环引用
__weak UITableView *tableView = self.tableView;
__weak typeof(self)weakSelf = self;
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshHouseData)];
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[weakSelf refreshHouseData];
}];
tableView.mj_header = header;
//自定义文字
[header setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
[header setTitle:@"松开就可以刷新的状态" forState:MJRefreshStatePulling];
[header setTitle:@"正在努力刷新中...." forState:MJRefreshStateRefreshing];
[header setTitle:@"刷新完毕,没有更多数据" forState:MJRefreshStateNoMoreData];
header.lastUpdatedTimeLabel.hidden = NO;//隐藏上次更新时间
header.stateLabel.hidden = NO;// 隐藏状态
//设置字体
header.stateLabel.font = [UIFont systemFontOfSize:15];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:15];
//设置颜色
header.stateLabel.textColor = [UIColor redColor];
header.lastUpdatedTimeLabel.textColor = [UIColor blueColor];
// 设置自动切换透明度(在导航栏下面自动隐藏)
header.automaticallyChangeAlpha = YES;
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreHouseData)];
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
[weakSelf loadMoreHouseData];
}];
tableView.mj_footer = footer;
[footer setTitle:@"上拉加载" forState:MJRefreshStateIdle];
[footer setTitle:@"松开就可以加载的状态" forState:MJRefreshStatePulling];
[footer setTitle:@"正在努力加载中...." forState:MJRefreshStateRefreshing];
[footer setTitle:@"加载完毕,没有更多数据" forState:MJRefreshStateNoMoreData];
// 拿到当前的上拉刷新控件,变为没有更多数据的状态
[tableView.mj_footer endRefreshingWithNoMoreData]
//隐藏当前上拉刷新控件 ,隐藏后就没有刷新控件
tableView.mj_footer.hidden = YES;
简单动画
tableView.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
[weakSelf refreshHouseData];
}];
[header setImages:imageArr1 forState:MJRefreshStateIdle];
[header setImages:imageArr2 forState:MJRefreshStateRefreshing];
webView
__weak UIWebView *webView = self.webView;
__weak UIScrollView *scrollView = self.webView.scrollView;
// 添加下拉刷新控件
scrollView.mj_header= [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[webView reload];
}];
#pragma mark - webViewDelegate
- (void)webViewDidFinishLoad:(nonnull UIWebView *)webView
{
[self.webView.scrollView.mj_header endRefreshing];
}