The code is as follows:
Code in. h:
////HKUIToolsView.h//Hkuitoolsdemo////Created by Ishakan on 2017/7/28.//Copyright 2017 Liuhuakun. All rights reserved.//#import<UIKit/UIKit.h>@interfaceHkuitoolsview:uiview/*Remove the view of the loaded type*/- (void) Removeloadviewfromsuperview;/** @msg input need prompt text * @typeNum Select control type///0 for Middle square text hint box 1 wait to load view 2 bottom bar text prompt box **/-(Instancetype) initWithFrame: (CGRect) frame withmsg: (NSString *) msg andtype: (Nsinteger) typenum;@end
Code in. M:
// // hkuitoolsview.m// hkuitoolsdemo//// Created by Ishakan on 2017/7/28. // Copyright 2017 Liuhuakun. All rights reserved. // #import " HKUIToolsView.h " @interface Hkuitoolsview () { *_loadviewtimeouttimer;} @end
@implementation Hkuitoolsview-(Instancetype) initWithFrame: (CGRect) frame withmsg: (NSString *) msg andtype: (Nsinteger) typenum{ = [Super Initwithframe:frame]; if (self) { *mainscreenbgview = [[UIView alloc] initwithframe:frame]; 0.3 ; = [Uicolor blackcolor]; [Self addsubview:mainscreenbgview]; [Self createview:frame andmsg:msg andtype:typenum]; } return Self ;}
//load medium and middle hints msg- (void) CreateView: (CGRect) frame andmsg: (NSString *) msg andtype: (nsinteger) typenum{cgfloat w,h,x,y; if(typenum==0|| typenum==1) {W= frame.size.width/3.0; H=W; X= (frame.size.width-w)/2.0; Y= (frame.size.height-h)/2.0; } Else{W= frame.size.width*0.6; H=60.0; X= (frame.size.width-w)/2.0; Y= frame.size.height-h-32.0; } UIView*centermsgview =[[UIView alloc] Initwithframe:cgrectmake (x, Y, W, h)]; Centermsgview.backgroundcolor=[Uicolor Blackcolor]; CenterMsgView.layer.masksToBounds=YES; CenterMsgView.layer.cornerRadius=8.0; [Self addsubview:centermsgview]; if(typenum==0|| typenum==2) {cgfloat label_x,label_y,label_w,label_h; Label_x= Label_y =8; Label_w= W -; Label_h= h -; UILabel*msglabel =[[UILabel alloc] Initwithframe:cgrectmake (label_x, label_y, Label_w, Label_h)]; Msglabel.backgroundcolor=Centermsgview.backgroundcolor; Msglabel.textcolor=[Uicolor Whitecolor]; Msglabel.font= [Uifont systemfontofsize: -]; Msglabel.text=msg; Msglabel.numberoflines=0; Msglabel.textalignment=Nstextalignmentcenter; [Centermsgview Addsubview:msglabel]; [UIView animatewithduration:2.5animations:^{Self.alpha=0; [Nstimer scheduledtimerwithtimeinterval:3.0target:self selector: @selector (removeslef:) Userinfo:nil Repeats:no]; }]; } Else//Load View{cgfloat Actindview_w= W +; CGFloat Actindview_h= h +; CGFloat actindview_x= -; CGFloat actindview_y=0; Uiactivityindicatorview*activityindicatorview =[[Uiactivityindicatorview alloc] initwithactivityindicatorstyle:uiactivityindicatorviewstylewhitelarge]; Activityindicatorview.frame=CGRectMake (actindview_x, actindview_y, Actindview_w, actindview_h); Activityindicatorview.backgroundcolor=[Uicolor Blackcolor]; Activityindicatorview.tag=111; [Activityindicatorview startanimating]; [Centermsgview Addsubview:activityindicatorview]; CGFloat acindlabel_w,acindlabel_h,acindlabel_x,acindlabel_y; Acindlabel_x=actindview_x; Acindlabel_y= actindview_h*2/3.0; Acindlabel_w=Actindview_w; Acindlabel_h= actindview_h/3.0; UILabel*msglabel =[[UILabel alloc] Initwithframe:cgrectmake (acindlabel_x, acindlabel_y, Acindlabel_w, Acindlabel_h)]; Msglabel.backgroundcolor=[Uicolor Blackcolor]; Msglabel.textcolor=[Uicolor Whitecolor]; Msglabel.textalignment=Nstextalignmentcenter; Msglabel.text=msg; Msglabel.font= [Uifont systemfontofsize:14.0]; [Centermsgview Addsubview:msglabel]; _loadviewtimeouttimer= [Nstimer scheduledtimerwithtimeinterval:8target:self Selector: @selector (Removeloadviewfromsuperview) Userinfo:nil Repeats:no]; } }
- (void) Removeslef: (Nstimer *) timer{[timer invalidate]; [Self Removefromsuperview];}//Load Timeout hidden- (void) removeloadviewfromsuperview{if([_loadviewtimeouttimer isValid]) {[_loadviewtimeouttimer invalidate]; } [UIView animatewithduration:1.5animations:^{Self.alpha=0; [Nstimer scheduledtimerwithtimeinterval:2.0target:self selector: @selector (removeloadview:) Userinfo:nil Repeats:no]; }];}- (void) Removeloadview: (Nstimer *) timer{[timer invalidate]; Uiactivityindicatorview*indicatorview = [Self Viewwithtag:111]; [Indicatorview stopanimating]; [Self Removefromsuperview];}@end
At the interface where the corresponding control needs to be called,
////VIEWCONTROLLER.M//Hkuitoolsdemo////Created by Ishakan on 2017/7/28.//Copyright 2017 Liuhuakun. All rights reserved.//#import "ViewController.h"#import "HKUIToolsView.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib. }-(Ibaction) Centerpointviewshowbtnclick: (UIButton *) sender{[self showtoolmsg:@"Center prompt information Display! "ViewTag:sender.tag];}-(Ibaction) Loadviewshow: (UIButton *) sender{[self showtoolmsg:@"Loading in ..."ViewTag:sender.tag];}-(Ibaction) Bottompointviewshow: (UIButton *) sender{[self showtoolmsg:@"Tips at the bottom of the message! "ViewTag:sender.tag];}- (void) Showtoolmsg: (NSString *) msg Viewtag: (nsinteger) viewtag{Hkuitoolsview*toolsview =[[Hkuitoolsview alloc] Initwithframe:[uiscreen mainscreen].bounds withmsg:msg Andtype:viewtag]; Toolsview.tag=222; [[UIApplication Sharedapplication].keywindow Addsubview:toolsview];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end
iOS customizing some hint controls