IOS 仿Android吐司提示框的实例(分享)
直接上代码
#import@interfaceShowToastView:UIView +(void)showToastView:(UIView*)uiviewWithMessage:(NSString*)message; +(void)showToastViewShort:(UIView*)uiviewWithMessage:(NSString*)message; +(void)showToastViewWithCostUpload:(UIView*)uiviewWithMessage:(NSString*)message; +(void)showSmallHeightToastView:(UIView*)uiviewWithMessage:(NSString*)message; @end
#import"ShowToastView.h" @implementationShowToastView //Toast提示框 +(void)showToastView:(UIView*)uiviewWithMessage:(NSString*)message { UIView*showview=[[UIViewalloc]init]; showview.backgroundColor=[UIColorcolorWithRed:0green:0blue:0alpha:.3]; showview.frame=CGRectMake(1,1,1,1); showview.layer.cornerRadius=5.0f; showview.layer.masksToBounds=YES; [uiviewaddSubview:showview]; UILabel*label=[[UILabelalloc]init]; CGSizeLabelSize=[messagesizeWithFont:[UIFontsystemFontOfSize:17]constrainedToSize:CGSizeMake(290,9000)]; label.frame=CGRectMake(10,5,LabelSize.width,LabelSize.height); label.text=message; label.textColor=[UIColorwhiteColor]; label.textAlignment=1; label.backgroundColor=[UIColorclearColor]; label.font=[UIFontboldSystemFontOfSize:font(15)]; [showviewaddSubview:label]; showview.frame=CGRectMake((uiview.frame.size.width-LabelSize.width-20)/2,uiview.frame.size.height-LabelSize.height-100,LabelSize.width+20,LabelSize.height+10); [UIViewanimateWithDuration:5.0animations:^{ showview.alpha=0; }completion:^(BOOLfinished){ [showviewremoveFromSuperview]; }]; } +(void)showToastViewShort:(UIView*)uiviewWithMessage:(NSString*)message { UIView*showview=[[UIViewalloc]init]; showview.backgroundColor=[UIColorwhiteColor]; showview.frame=CGRectMake(1,1,1,1); showview.layer.cornerRadius=5.0f; showview.layer.masksToBounds=YES; [uiviewaddSubview:showview]; UILabel*label=[[UILabelalloc]init]; CGSizeLabelSize=[messagesizeWithFont:[UIFontsystemFontOfSize:17]constrainedToSize:CGSizeMake(290,9000)]; label.frame=CGRectMake(10,5,LabelSize.width,LabelSize.height); label.text=message; label.textColor=[UIColorblackColor]; label.textAlignment=1; label.backgroundColor=[UIColorclearColor]; label.font=[UIFontboldSystemFontOfSize:15]; [showviewaddSubview:label]; showview.frame=CGRectMake((uiview.frame.size.width-LabelSize.width-20)/2,uiview.frame.size.height-LabelSize.height-60,LabelSize.width+20,LabelSize.height+10); [UIViewanimateWithDuration:1animations:^{ showview.alpha=0; }completion:^(BOOLfinished){ [showviewremoveFromSuperview]; }]; } //费用提报的Toast位置往上放一点 +(void)showToastViewWithCostUpload:(UIView*)uiviewWithMessage:(NSString*)message { UIView*showview=[[UIViewalloc]init]; showview.backgroundColor=[UIColorcolorWithRed:0green:0blue:0alpha:.3]; showview.frame=CGRectMake(1,1,1,1); showview.layer.cornerRadius=5.0f; showview.layer.masksToBounds=YES; [uiviewaddSubview:showview]; UILabel*label=[[UILabelalloc]init]; CGSizeLabelSize=[messagesizeWithFont:[UIFontsystemFontOfSize:17]constrainedToSize:CGSizeMake(290,9000)]; label.frame=CGRectMake(10,5,LabelSize.width,LabelSize.height); label.text=message; label.textColor=[UIColorwhiteColor]; label.textAlignment=1; label.backgroundColor=[UIColorclearColor]; label.font=[UIFontboldSystemFontOfSize:font(15)]; [showviewaddSubview:label]; showview.frame=CGRectMake((uiview.frame.size.width-LabelSize.width-20)/2,uiview.frame.size.height-LabelSize.height-100,LabelSize.width+20,LabelSize.height+10); [UIViewanimateWithDuration:3.0animations:^{ showview.alpha=0; }completion:^(BOOLfinished){ [showviewremoveFromSuperview]; }]; } //点击开始按钮的时候提示没有任务,但是由于字数太多,高度又和宽度有一定的对比,所以在这里改成小一点高度 +(void)showSmallHeightToastView:(UIView*)uiviewWithMessage:(NSString*)message { UIView*showview=[[UIViewalloc]init]; showview.backgroundColor=[UIColorcolorWithRed:0green:0blue:0alpha:.3]; showview.frame=CGRectMake(1,1,1,1); showview.layer.cornerRadius=5.0f; showview.layer.masksToBounds=YES; [uiviewaddSubview:showview]; UILabel*label=[[UILabelalloc]init]; CGSizeLabelSize=[messagesizeWithFont:[UIFontsystemFontOfSize:17]constrainedToSize:CGSizeMake(290,9000)]; label.frame=CGRectMake(10,0,LabelSize.width,LabelSize.height); label.text=message; label.textColor=[UIColorwhiteColor]; label.textAlignment=1; label.backgroundColor=[UIColorclearColor]; label.font=[UIFontboldSystemFontOfSize:font(15)]; [showviewaddSubview:label]; showview.frame=CGRectMake((uiview.frame.size.width-LabelSize.width-20)/2,uiview.frame.size.height-LabelSize.height-60,LabelSize.width+20,LabelSize.height-5); [UIViewanimateWithDuration:5.0animations:^{ showview.alpha=0; }completion:^(BOOLfinished){ [showviewremoveFromSuperview]; }]; } @end
使用方法
[ShowToastViewshowToastView:self.viewWithMessage:@"用户名或密码错误"];
以上这篇IOS仿Android吐司提示框的实例(分享)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。