IOS MJRefresh pull-down refresh pull-up and load (you can add a gif) Summary

Source: Internet
Author: User

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.



 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.