In the actual development of the message prompt is very common requirements, in order to personalize and have a concise UI status bar hint is a good solution, a lot of benefits such as: do not block the main UI, new ideas, put the implementation code below.
The whc_statusbarmessage.h header files are as follows:
////WHCSTATUSBARMESSAGE.M//Whcstatusbarmessage////Created by Apple on 14-3-28.//Copyright (c) 2014 Apple. All rights reserved.//#import "whc_statusbarmessage.h" #define KPADING (5.0)//margin#define KLOGOWIDTH (15.0)//Icon logo width @interface whc_statusbarmessage() { UILabel* MSGLAB;//Message Labels Uiimageview* LOGOIMGV;//logo Icon Object UIImage* LOGOIMG;//logo icon CGFloatHeight//Height CGFloatScreenWidth;//Screen width CGFloatScreenHeight;//Screen height}@property(nonatomic, retain)UILabel* STATUSLAB;@property(nonatomic, retain)Uiimageview* Logimgview;@property(nonatomic, retain) Nstimer * Runtimer;//Dwell clock@end @implementation whc_statusbarmessage StaticWhc_statusbarmessage * MSB;//Build a single case+ (Whc_statusbarmessage *) sharestatusbar{Static dispatch_once_tOncetoken;dispatch_once(&oncetoken, ^{MSB = [[Whc_statusbarmessage alloc]init]; });returnMSB;}//Initialize UI-(ID) init{CGRectStatusframe = [uiapplicationSharedapplication]. Statusbarframe; Height = Statusframe. Size. Height; ScreenWidth = [UIScreen mainscreen]. Bounds. Size. Width; ScreenHeight = [UIScreen mainscreen]. Bounds. Size. Height; Self= [SuperInitwithframe:statusframe];if( Self){ Self. Frame= Statusframe; Self. Autoresizingmask= Uiviewautoresizingflexiblewidth; Self. Windowlevel= Uiwindowlevelstatusbar +1.0; Self. BackgroundColor= Kwhc_statusbarmessageback_color; Logoimg = [UIImageimagewithcontentsoffile:[[NSBundleMainbundle] pathforresource:@"29x29"oftype:@"PNG"]]; LOGOIMGV = [[UiimageviewAlloc]initwithframe:cgrectmake (kpading, kpading/2.0, Klogowidth, Klogowidth)]; Logoimgv. BackgroundColor= [UicolorClearcolor]; [ SelfADDSUBVIEW:LOGOIMGV]; Msglab = [[UILabelAlloc]initwithframe:cgrectmake (LOGOIMGV. Frame. Origin. x+ kpading + LOGOIMGV. Frame. Size. Width,0.0, ScreenWidth-(LOGOIMGV. Frame. Origin. x+ kpading + LOGOIMGV. Frame. Size. Width), Statusframe. Size. Height)]; Msglab. BackgroundColor= [UicolorClearcolor]; Msglab. Font= [UifontSystemfontofsize:14.0]; Msglab. TextColor= [UicolorWhitecolor]; [ SelfAddsubview:msglab];//Register Click eventUITapGestureRecognizer * Tapstatusbar = [[UITapGestureRecognizer alloc]initwithtarget: SelfAction@selector(Taptopbar:)]; [ SelfAddgesturerecognizer:tapstatusbar];//Register status bar Direction listener event[[NsnotificationcenterDefaultcenter]addobserver: SelfSelector@selector(Screenorientationchange:) Name:uiapplicationwillchangestatusbarframenotification object:Nil]; }return Self;}//Processing click status bar Messages- (void) Taptopbar: (UITapGestureRecognizer *) tapgesture{if(_whcstatusbardelegate && [_whcstatusbardelegate respondstoselector:@selector(didtaptouchwhcstatusbarmessagedosomething)]) {[_whcstatusbardelegate didtaptouchwhcstatusbarmessagedosomething]; }}//Display status bar messages-(void) Showtextmessage: (NSString*) strmessage Delaytime: (Nsinteger) delay{[ Self. RuntimerInvalidate]; Self. Runtimer=Nil;if(Logoimg = =Nil) {logoimg = [UIImageimagewithcontentsoffile:[[NSBundleMainbundle] pathforresource:@"29x29"oftype:@"PNG"]]; }if(Delay = =-1) delay =3; Logoimgv. Image= Logoimg; Msglab. Text= strmessage; __blockCGRectStateframe = Self. Frame; Stateframe. Origin. Y= -20.0; Self. Frame= Stateframe; [UIViewAnimatewithduration:0.2animations:^{Stateframe. Origin. Y=0.0; Self. Frame= Stateframe; }]; [ SelfMakekeyandvisible]; Self. Runtimer= [Nstimer scheduledtimerwithtimeinterval:delay target: SelfSelector@selector(Dismisstimer) UserInfo:NilRepeatsNO];} -(void) ShowMessage: (NSString*) strmessage Logimage: (UIImage*) Logimage Delaytime: (Nsinteger) delay{logoimg = Logimage; [ SelfShowtextmessage:strmessage Delaytime:delay];} -(void) dismisstimer{DoubleDelayinseconds =0.3; dispatch_time_t poptime = Dispatch_time (Dispatch_time_now, (int64_t) (Delayinseconds * nsec_per_sec)); Dispatch_after (Poptime, Dispatch_get_main_queue (), ^ (void) {MSB. Hidden=YES; });}#pragma mark-screenchange-(void) Screenorientationchange: (nsnotification*) notif{uiinterfaceorientationorientation = [[[Notif UserInfo] objectforkey:uiapplicationstatusbarorientationuserinfokey] integervalue];Switch(orientation) { CaseUiinterfaceorientationportrait: Self. Transform= Cgaffinetransformidentity; Self. Frame= CGRectMake (0.0,0.0, screenwidth, height); Break; CaseUiinterfaceorientationportraitupsidedown: Self. Transform= Cgaffinetransformmakerotation (M_PI); Self. Center= Cgpointmake (ScreenWidth/2.0, Screenheight-height/2.0); Self. Bounds= CGRectMake (0.0,0.0, screenwidth, height); Break; CaseUiinterfaceorientationlandscapeleft: Self. Transform= Cgaffinetransformmakerotation (-m_pi_2); Self. Center= Cgpointmake (Height/2.0, ScreenHeight/2.0); Self. Bounds= CGRectMake (0.0,0.0, screenheight, height); Break; CaseUiinterfaceorientationlandscaperight: Self. Transform= Cgaffinetransformmakerotation (m_pi_2); Self. Center= Cgpointmake (Screenwidth-height/2.0, ScreenHeight/2.0); Self. Bounds= CGRectMake (0.0,0.0, screenheight, height); Break;default: Break; }}@end
Common custom control development set for iOS development series-Custom status bar message tip control development