Three ways to set the time auto-disappear prompt in iOS

Source: Internet
Author: User



  ============================================================================== #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

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.