IOS MJRefresh pull-down refresh pull-up and load (you can add a gif) Summary
1. First download the latest MJ refresh library on github. Download the MJ Link
2. Add related code to tableVIew
_ TableView = [[UITableView alloc] initWithFrame: CGRectMake (0, 0, MCAPPWidth, MCAPPHeight-64)];
_ TableView. backgroundColor = myClearColor;
_ TableView. separatorStyle = UITableViewCellSeparatorStyleNone;
_ TableView. delegate = self;
_ TableView. dataSource = self;
_ TableView. showsVerticalScrollIndicator = NO;
_ TableView. scrollsToTop = YES;
[Self. view addSubview: _ tableView];
[_ TableView addGifHeaderWithRefreshingTarget: self refreshingAction: @ selector (loadData)];
[_ TableView addGifFooterWithRefreshingTarget: self refreshingAction: @ selector (loadMoreData)];
[Self gif];
// LoadData: The method for requesting network data when you pull down and refresh the Refresh. loadMoreData is the method for requesting network data when you pull and load the data.
3. [self gif]
-(Void) gif
{
NSMutableArray * idleImages = [NSMutableArray array];
// This gif image appears when you refresh it. It needs to be added to the array cyclically.
For (NSUInteger I = 1; I <= 5; I ++ ){
UIImage * image = [UIImage imageNamed: [NSString stringWithFormat: @img_loading-%lu.png, (unsigned long) I];
[IdleImages addObject: image];
}
Pai_tableview.gif Header setImages: idleImages forState: MJRefreshHeaderStateIdle];
_TableView.gif Footer. refreshingImages = idleImages;
_TableView.gif Header. updatedTimeHidden = YES;
// Set the animation image to be refreshed (the status will be refreshed when it is released)
NSMutableArray * refreshingImages = [NSMutableArray array];
For (NSUInteger I = 1; I <= 5; I ++ ){
UIImage * image = [UIImage imageNamed: [NSString stringWithFormat: @img_loading-%lu.png, (unsigned long) I];
[RefreshingImages addObject: image];
}
Pai_tableview.gif Header setImages: refreshingImages forState: MJRefreshHeaderStatePulling];
}
4. Customize the Label and gif frame at the bottom of the top when refreshing. Here is an example of footer.
MJRefreshGifFooter. m
-(Void) layoutSubviews
{
[Super layoutSubviews];
// Specifies the frame of the gif image.
Self.gif View. frame = CGRectMake (self. bounds. origin. x + 20, self. bounds. origin. y + 15, self. bounds. size. width/2, self. bounds. size. height/2 );
If (self. stateHidden ){
Self.gif View. contentMode = UIViewContentModeCenter;
} Else {
Self.gif View. contentMode = UIViewContentModeScaleAspectFit;
Self.gif View. mj_w = self. mj_w * 0.5-90;
}
}
MJRefreshFooter. m
-(Void) layoutSubviews
{
[Super layoutSubviews];
Self. loadMoreButton. frame = self. bounds;
Self. loadMoreButton. hidden = YES;
// Frame of the Label
Self. stateLabel. frame = CGRectMake (self. bounds. origin. x, self. bounds. origin. y + 15, self. bounds. size. width, self. bounds. size. height/2 );
Self. noMoreLabel. frame = self. bounds;
}
Similarly, the gif frame and Labelframe of the header can be modified as needed in the methods in the corresponding class.
For more settings, refer to MJ's documentation on github.