iOS refreshes the basic use of third-party Mjrefresh

Source: Internet
Author: User

The best use of refresh third-party framework in IOS development Mjrefresh

Github:https://github.com/codermjlee/mjrefresh

Introduction of Uirefreshcontrol

1,uirefresh is Apple's own refresh control
2, support version after iOS6.0
3, once assigned to a Uitableviewcontroller, the control's frame is automatically managed

Uirefreshcontrol Basic Use
Refresh in the state to judge, read-only properties, depending on the state can do some custom things@property (Nonatomic,ReadOnly, getter=isrefreshing)BOOL refreshing;Instantiating an object (with Init,uirefreshcontrol initialization)Uirefreshcontrol *control = [[Uirefreshcontrol alloc] init];//Set the color (chrysanthemum and text) of the Uirefreshcontrol control. tintcolor = [uicolor redcolor]; ///Added to TableView, the default size and location are already set [self. TableView Addsubview:control]; //drop-down Refresh text description, custom @property (nonatomic, retain) nsattributedstring *attributedtitle//Start Refresh-(  void) beginrefreshing ns_available_ios (6_0);  Ends the refresh, called after determining that the desired load data is obtained (void) endrefreshing ns_available_ios (6_0);      
Introduction of Mjrefresh

Mjrefresh is a custom refresh control that inherits from UIView
Which controls are supported for refresh?
Uiscrollview, UITableView, Uicollectionview, UIWebView
After iOS9, using the Mjrefresh framework with its properties and methods, most need to add the mj_ to the beginning as a prefix

  • The Frame pure arc, compatible system >=ios6.0, Iphone\ipad screen
If you use Mjrefresh

Cocoapods import: Pod ' Mjrefresh ' (cocoapods another blog has written)
Manual import:
To drag all the files in the Mjrefresh folder into the project
Import Primary header file: #import "MJREFRESH.H"

#主要是实现上拉刷新和下拉刷新Drop-down RefreshSelf. TableView. Mj_header = [Mjrefreshnormalheader headerwithrefreshingtarget:Self refreshingaction:@selector (Loadnewtopic)];Automatically change transparencySelf. TableView.mj_header.automaticallychangealpha = yes; //into refresh status [self.tableView.mj_header beginrefreshing]; //pull up refresh self.tableView.mj_footer = [Mjrefreshbacknormalfooter footerwithrefreshingtarget: self refreshingaction: @selector (loadmoretopic)]; //end head Refresh [Weakself.tableview.mj_ Header endrefreshing]; //end tail Refresh [Weakself.tableview . Mj_footer endrefreshing];              
Mjrefresh class structure diagram
Mjv587.png
Mj87v5.png using the default drop-down Refresh-01
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{        // 进入刷新状态后会自动调用这个block    }];    //或 // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法) self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)]; // 马上进入刷新状态 [self.tableView.header beginRefreshing];

[


(Drop-down Refresh 01-normal) Pull picture Refresh-02
        Refresh the state of the controltypedefNs_enum (Nsinteger, Mjrefreshstate) {/** Normal Idle state */Mjrefreshstateidle =1,/** release can be refreshed status */Mjrefreshstatepulling,/** is refreshing in the state */mjrefreshstaterefreshing,/** the state of the upcoming refresh */Mjrefreshstatewillrefresh,/** all data loaded, no more data */mjrefreshstatenomoredata}; //Set callback (once in the refresh state, call Target's action, that is, call Self's Loadnewdata method) Mjrefreshgifheader *header = [Mjrefreshgifheader Headerwithrefreshingtarget: Selfrefreshingaction:@selector (Loadnewdata)]; //Set an animated picture of the normal state (Idleimages is a picture) [Header setimages:idleimages Forstate:mjrefreshstateidle]; //Set an animated picture of the state to be refreshed (a state that will refresh as soon as it is released) [Header Setimages:pullingimages forstate:mjrefreshstatepulling]; //Set animated picture to be refreshed [header setimages:refreshingimages forstate:mjrefreshstaterefreshing]; //Set header self. TableView. Mj_header = header;          

[


(drop-down refresh 02-animated picture) dropdown hidden Properties
// 隐藏时间header.lastUpdatedTimeLabel.hidden = YES;// 隐藏状态header.stateLabel.hidden = YES;
Customize settings for text and animated pictures
#使用上拉刷新和下拉刷新一般都是自定义头部和尾部的类例如: The head refreshes@interfaceJhheader:Mjrefreshnormalheader#在 settings in. m files/** Initialization Settings */-(void) prepare{[Super Prepare];Create UiimageviewUiimageview *logoview = [[Uiimageview alloc] init];Add Picture Logoview. image = [UIImage imagenamed:@ "Meinv02"];Add the Uiimageview to the current header [Self Addsubview:logoview];Self. Logoview = Logoview;Automatically toggle transparency based on drag and dropSelf. Automaticallychangealpha =YES;Hide TimeSelf. Lastupdatedtimelabel. Hidden =YES;Set Text colorSelf. Statelabel. TextColor = [uicolor Redcolor];} /** * Placing child controls */-(void) placesubviews{[ super placesubviews]; self.logoview.x = 0; self.logoview.width = self.width; self.logoview.height = 100; self.logoview.Y =-self.logoview.height;}     
Custom Tail Refresh
Example: Creating a Jhfooter class inherits from Mjrefreshautonormalfooter@interfaceJhfooter:Mjrefreshautonormalfooter#在 settings in. m files/** Initialize */-(void) prepare{[Super Prepare];Self. Statelabel. TextColor = [Uicolor Graycolor]; [Self Settitle:@ "Pull up to load more content oh ..." forstate:mjrefreshstateidle]; [Self Settitle:@ "Connecting Network load ...." forstate:mjrefreshstaterefreshing];Uiswitch *swith = [[Uiswitch alloc] init]; [Self Addsubview:swith];Uiimageview *logoview = [[Uiimageview alloc] init]; Logoview. image = [UIImage imagenamed:@ "Meinv02"]; [Self Addsubview:logoview];self.logoview = Logoview;} /** * Placing child controls */-(void) placesubviews{[ super placesubviews]; self.logoview.x = 0; self.logoview.y = self.height; self.logoview.width = self.width; self.logoview.height = 100;}              

Most of the references from Mjrefresh readme.md
The framework also has a lot of powerful features that can be accessed at the top of the GitHub view
Given these should be enough to develop the usual, I hope that a lot of advice



The Dancing Lion (Jane book author)
Original link: Http://www.jianshu.com/p/e1a40f46aed7
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

iOS refreshes the basic use of third-party Mjrefresh

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.