支持的控件
UITableView,UICollectionView,UIScrollView,UIWebView
下拉刷新
- Normal : MJRefreshNormalHeader
- Gif : MJRefreshGifHeader
上拉加載
- Normal : MJRefreshBackNormalFooter / MJRefreshAutoNormalFooter
- Gif : MJRefreshBackGifFooter / MJRefreshAutoGifFooter
使用時(shí)有Block 和 Target-Action兩種模式
基礎(chǔ)使用
//防止循環(huán)引用
__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:@"松開就可以刷新的狀態(tài)" forState:MJRefreshStatePulling];
[header setTitle:@"正在努力刷新中...." forState:MJRefreshStateRefreshing];
[header setTitle:@"刷新完畢,沒(méi)有更多數(shù)據(jù)" forState:MJRefreshStateNoMoreData];
header.lastUpdatedTimeLabel.hidden = NO;//隱藏上次更新時(shí)間
header.stateLabel.hidden = NO;// 隱藏狀態(tài)
//設(shè)置字體
header.stateLabel.font = [UIFont systemFontOfSize:15];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:15];
//設(shè)置顏色
header.stateLabel.textColor = [UIColor redColor];
header.lastUpdatedTimeLabel.textColor = [UIColor blueColor];
// 設(shè)置自動(dòng)切換透明度(在導(dǎo)航欄下面自動(dòng)隱藏)
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:@"松開就可以加載的狀態(tài)" forState:MJRefreshStatePulling];
[footer setTitle:@"正在努力加載中...." forState:MJRefreshStateRefreshing];
[footer setTitle:@"加載完畢,沒(méi)有更多數(shù)據(jù)" forState:MJRefreshStateNoMoreData];
// 拿到當(dāng)前的上拉刷新控件,變?yōu)闆](méi)有更多數(shù)據(jù)的狀態(tài)
[tableView.mj_footer endRefreshingWithNoMoreData]
//隱藏當(dāng)前上拉刷新控件 此再,隱藏后就沒(méi)有刷新控件
tableView.mj_footer.hidden = YES;
簡(jiǎn)單動(dòng)畫
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];
}