//Create a new class#import<UIKit/UIKit.h>typedef ns_enum (Nsinteger, Xfnoticesstyle) {xfnoticesstylesuccess=0, Xfnoticesstylefail=1,};@interfaceXfnotices:uiview//Create a method+(void) Noticeswithtitle: (NSString *) title time: (nstimeinterval) Time View: (UIView *) View style: (Xfnoticesstyle) style;@endin the. m file#import "XFNotices.h"@interfacexfnotices () @property (nonatomic, strong) Uiimageview*image; @property (nonatomic, strong) UILabel*message; @property (nonatomic, strong) Nsdictionary*dic;@end@implementationxfnotices-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {[self setupview]; } returnSelf ;}
- (void) setupview{Self.backgroundcolor= [Uicolor colorwithwhite:0.1Alpha0.9]; Self.image=[[Uiimageview alloc]init]; _image.frame= CGRectMake ( the,Ten, +, +); _image.image= [UIImage imagenamed:@"Success"]; [Self addsubview:_image]; Self.message=[[UILabel alloc]init]; _message.frame= CGRectMake (Ten, $, the, -); _message.textalignment=Nstextalignmentcenter; _message.textcolor=[Uicolor Whitecolor]; _message.numberoflines=0; [Self addsubview:_message]; }+(void) Noticeswithtitle: (NSString *) title time: (nstimeinterval) Time View: (UIView *) View Style: (xfnoticesstyle) style{xfnotices*notices = [[Xfnotices alloc]initwithframe:cgrectmake (0,0, -, the)]; Switch(style) { Case 0: Notices.image.image= [UIImage imagenamed:@"Success"]; Break; Case 1: Notices.image.image= [UIImage imagenamed:@"fail"]; default: Break; } notices.center= Cgpointmake (View.bounds.size.width/2, view.bounds.size.height/2- -); Notices.layer.masksToBounds=YES; Notices.layer.cornerRadius= the; Notices.dic= [Nsdictionary dictionarywithobject:notices forkey:@"DD"]; Notices.message.text=title; Notices.message.font= [Uifont systemfontofsize: A]; Notices.alpha=0; [UIView animatewithduration:0.5animations:^{Notices.center= Cgpointmake (View.bounds.size.width/2, view.bounds.size.height/2- -); [View Addsubview:notices]; Notices.alpha=0.7; }]; [Nstimer scheduledtimerwithtimeinterval:time target:self selector: @selector (timeaction:) userInfo:notices.dic Repeats:no]; }+ (void) Timeaction: (Nstimer *) sender{xfnotices*notices = [[Sender UserInfo] Valueforkey:@"DD"]; [UIView animatewithduration:0.5animations:^{Notices.alpha=0; } Completion:^(BOOL finished) {[Notices Removefromsuperview]; }]; }@end
Customizing write a prompt box