Customizing write a prompt box

Source: Internet
Author: User

//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

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.