Class method:
+ (void) ShowMessage: (NSString *) Message {//Get WindowUIWindow *window =[UIApplication Sharedapplication].keywindow; UIView*showview =[[UIView alloc] init]; Showview.backgroundcolor=[Uicolor Blackcolor]; 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]; Uifont*font = [Uifont systemfontofsize: the]; CGRect Labelrect= [Message Boundingrectwithsize:cgsizemake (290, Cgfloat_max) Options:nsstringdrawinguseslinefragmentorigin Attributes:@{nsfontattributename:font} context: NIL]; Label.frame= CGRectMake (Ten,5, Cgrectgetwidth (Labelrect), Cgrectgetheight (Labelrect)); Label.text=message; Label.textcolor=[Uicolor Whitecolor]; Label.textalignment=Nstextalignmentcenter; Label.backgroundcolor=[Uicolor Clearcolor]; [ShowView Addsubview:label]; Showview.frame= CGRectMake ((screen_width-cgrectgetwidth (Labelrect)- -)/2, Screen_height- -, Cgrectgetwidth (Labelrect) + -, Cgrectgetheight (Labelrect) +Ten); [UIView animatewithduration:1.5animations:^{Showview.alpha=0; } Completion:^(BOOL finished) {[ShowView Removefromsuperview]; }]; }
Implement a similar Android auto-vanishing prompt box in iOS