============================================================================== #pragma mark-a message that shows a custom view, disappears periodically ==============================================================================+ (void) ShowMessage: (NSString *) Message Duration: (nstimeinterval) time{cgsize screensize = [[UIScreen mainscreen] bounds].size; UIWindow * window = [UIApplication sharedapplication].keywindow; UIView *showview = [[UIView alloc]init]; Showview.backgroundcolor = [Uicolor Graycolor]; Showview.frame = CGRectMake (1, 1, 1, 1); Showview.alpha = 1.0f; Showview.layer.cornerRadius = 5.0f; Showview.layer.masksToBounds = YES; [Window Addsubview:showview]; UILabel *label = [[UILabel alloc]init]; Nsmutableparagraphstyle *paragraphstyle = [[Nsmutableparagraphstyle alloc]init]; Paragraphstyle.linebreakmode = nslinebreakbywordwrapping; Nsdictionary *attributes = @{nsfontattributename:[uifont systemfontofsize:15.f], Nsparag RaphstyleAttributeName:paragraphStyle.copy}; Cgsize labelsize = [Message Boundingrectwithsize:cgsizemake (207, 999) options: Nsstringdrawinguseslinefragmentorigin attributes:attributes Context:nil].s Ize Label.frame = CGRectMake (Ten, 5, Labelsize.width +20, labelsize.height); Label.text = message; Label.textcolor = [Uicolor Whitecolor]; Label.textalignment = 1; Label.backgroundcolor = [Uicolor Clearcolor]; Label.font = [Uifont boldsystemfontofsize:15]; [ShowView Addsubview:label]; Showview.frame = CGRectMake ((screensize.width-labelsize.width-20)/2, Screensize.hei ght-100, labelsize.width+40, labelSize.h EIGHT+10); [UIView animatewithduration:time animations:^{showview.alpha = 0; } completion:^ (BOOL finished) {[ShowView RemovefromsupeRview]; }];} ============================================================================== #pragma mark-Two, Display Uialert window message, Timed Disappearance//==============================================================================//------------------------- -----------------------------------------------------#pragma mark-1, external call interface//----------------------------------- -------------------------------------------+ (void) Showalert: (NSString *) message Duration: (nstimeinterval) time{ Uialertview *promptalert = [[Uialertview alloc] initwithtitle:@ "prompt:" Message:message Delegate:nil Cancelbuttontitle:nil Otherbuttontitles:nil]; [Nstimer scheduledtimerwithtimeinterval:time Target:self Selector: @selector (timerfiremethod:) Userinfo:promptalert Repeats:yes]; [Promptalert show];} ------------------------------------------------------------------------------#pragma the callback method for the Mark-2, external call interface//--- ---------------------------------------------------------------------------+ (void) Timerfiremethod: (nstimer*) thetimer//pop-up box {Uialertview *promptalert = (uialertview*) [Thetimer UserInfo]; [Promptalert dismisswithclickedbuttonindex:0 Animated:no]; Promptalert = NULL;} ============================================================================== #pragma mark-Three, Display Uialert window message, Timed Disappearance//==============================================================================//------------------------- -----------------------------------------------------#pragma mark-1, external call interface//----------------------------------- -------------------------------------------+ (void) Showalertmessagewithmessage: (nsstring*) message Duration: ( Nstimeinterval) time{Uialertview *alert = [[UialertviewALLOC] initwithtitle:@ "hint:" Message:message delegate:nil cancelbuttontitle:nil OT Herbuttontitles:nil]; [Alert show]; [Self performselector: @selector (dimissalert:) Withobject:alert afterdelay:time];} ------------------------------------------------------------------------------#pragma the callback method for the Mark-2, external call interface//--- ---------------------------------------------------------------------------+ (void) Dimissalert: (Uialertview *) Alert {if (alert) {[Alert Dismisswithclickedbuttonindex:[alert cancelbuttonindex] animated:yes]; }}//------------------------------------------------------------------------------
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Three ways to set the time auto-disappear prompt in iOS