iOS Load Wait indicator (tool Class)

Source: Internet
Author: User

#import "CXDView.h"@interfaceCxdview ()//Dynamic Graphs@property (Strong, nonatomic) Uiimageview *Loadingimageview;//hint Text@property (Strong, nonatomic) UILabel *Toastlabel;@end@implementationCxdview#pragmaMark-Initialize-(instancetype) init{ Self=[Super Init]; if(self) {[self addSubview:self.loadingImageView];    [Self AddSubview:self.toastLabel]; }    returnSelf ;}#pragmaMark-Interface method//To which interface to load the loading interface+ (void) Showcxdviewfromsuperview: (UIView *) superview{[self showcxdviewfromsuperview:superview offsetY:0];}//which interface to remove the loading interface from+ (void) Removecxdviewfromsuperview: (UIView *) superview{//Find in "All Child view arrays" in parent view     for(UIView *itemviewinchsuperview.subviews) {//If a child view is a Cxdview type        if([Itemview Iskindofclass:[cxdviewclass]]) {            //to remove it from the parent view[Itemview Removefromsuperview]; }    }}//To which interface to load the loading interface (exactly how many locations)+ (void) Showcxdviewfromsuperview: (UIView *) Superview OffsetY: (cgfloat) offsety{Cxdview*loadingview =[[Cxdview alloc] init]; Loadingview.frame= CGRectMake ([UIScreen mainscreen].bounds.size.width/2- +, [UIScreen mainscreen].bounds.size.height/2- ++offsety, the, -);//PS: No effect because ImageView and label are not operable and the custom view background is transparent//PSS: If the control is operational and beyond the view range, the operation cannot be resumed//determine if a cxdview is already present on the Superview//if it already exists, delete the Cxdview first[self removecxdviewfromsuperview:superview]; //load the new view again[Superview Addsubview:loadingview]; //let the dynamic graph move.[Loadingview.loadingimageview startanimating]; }#pragmaMark-Lazy Loading-(Uiimageview *) loadingimageview{if(!_loadingimageview) {_loadingimageview=[[Uiimageview alloc] init]; _loadingimageview.frame= CGRectMake (0,0, the, the); _loadingimageview.backgroundcolor=[Uicolor Clearcolor]; //Set Dynamic graph properties_loadingimageview.animationimages =[self getimagearray]; _loadingimageview.animationduration=2.0; _loadingimageview.animationrepeatcount=0; }    return_loadingimageview;}//get an array of pictures-(Nsarray *) getimagearray{//Get Picture nameNsmutablearray *imagenamearr =[Nsmutablearray array];  for(inti =1; I < -; i++) {NSString*ImageName; if(i<Ten) {ImageName= [NSString stringWithFormat:@"loading_animate_0%d", I]; }Else{imageName= [NSString stringWithFormat:@"loading_animate_%d", I];    } [Imagenamearr Addobject:imagename]; }    //get an array of picturesNsmutablearray *imagearr =[Nsmutablearray array];  for(inti =0; I < the; i++) {NSString*imagename =[Imagenamearr objectatindex:i]; UIImage*image =[UIImage Imagenamed:imagename];    [Imagearr Addobject:image]; }        returnImagearr;}-(UILabel *) toastlabel{if(!_toastlabel) {_toastlabel=[[UILabel alloc] init]; _toastlabel.frame= CGRectMake (0, -, the, -); _toastlabel.text=@"A moment is coming ..."; _toastlabel.textcolor=[Uicolor Darkgraycolor]; _toastlabel.font= [Uifont systemfontofsize: -]; _toastlabel.textalignment=Nstextalignmentcenter; }    return_toastlabel;}@end

PS: Picture files need to be added by themselves

PSS: This class can be encapsulated to facilitate the display of wait instructions on the interface during request data, improving the user experience

iOS Load Wait indicator (tool Class)

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.