时间:2021-05-20
直接上代码
#import <UIKit/UIKit.h>@interface ShowToastView : UIView+(void)showToastView:(UIView *)uiview WithMessage:(NSString *)message;+(void)showToastViewShort:(UIView *)uiview WithMessage:(NSString *)message;+(void)showToastViewWithCostUpload:(UIView *)uiview WithMessage:(NSString *)message;+(void)showSmallHeightToastView:(UIView *)uiview WithMessage:(NSString *)message;@end#import "ShowToastView.h"@implementation ShowToastView//Toast提示框+(void)showToastView:(UIView *)uiview WithMessage:(NSString *)message{ UIView *showview = [[UIView alloc]init]; showview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3]; showview.frame = CGRectMake(1, 1, 1, 1); showview.layer.cornerRadius = 5.0f; showview.layer.masksToBounds = YES; [uiview addSubview:showview]; UILabel *label = [[UILabel alloc]init]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height); label.text = message; label.textColor = [UIColor whiteColor]; label.textAlignment = 1; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:font(15)]; [showview addSubview: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); [UIView animateWithDuration:5.0 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }];}+(void)showToastViewShort:(UIView *)uiview WithMessage:(NSString *)message{ UIView *showview = [[UIView alloc]init]; showview.backgroundColor = [UIColor whiteColor]; showview.frame = CGRectMake(1, 1, 1, 1); showview.layer.cornerRadius = 5.0f; showview.layer.masksToBounds = YES; [uiview addSubview:showview]; UILabel *label = [[UILabel alloc]init]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height); label.text = message; label.textColor = [UIColor blackColor]; label.textAlignment = 1; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:15]; [showview addSubview: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); [UIView animateWithDuration:1 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }];}//费用提报的Toast位置往上放一点+(void)showToastViewWithCostUpload:(UIView *)uiview WithMessage:(NSString *)message{ UIView *showview = [[UIView alloc]init]; showview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3]; showview.frame = CGRectMake(1, 1, 1, 1); showview.layer.cornerRadius = 5.0f; showview.layer.masksToBounds = YES; [uiview addSubview:showview]; UILabel *label = [[UILabel alloc]init]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height); label.text = message; label.textColor = [UIColor whiteColor]; label.textAlignment = 1; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:font(15)]; [showview addSubview: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); [UIView animateWithDuration:3.0 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }];}//点击开始按钮的时候提示没有任务,但是由于字数太多,高度又和宽度有一定的对比,所以在这里改成小一点高度+(void)showSmallHeightToastView:(UIView *)uiview WithMessage:(NSString *)message{ UIView *showview = [[UIView alloc]init]; showview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3]; showview.frame = CGRectMake(1, 1, 1, 1); showview.layer.cornerRadius = 5.0f; showview.layer.masksToBounds = YES; [uiview addSubview:showview]; UILabel *label = [[UILabel alloc]init]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 0, LabelSize.width, LabelSize.height); label.text = message; label.textColor = [UIColor whiteColor]; label.textAlignment = 1; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:font(15)]; [showview addSubview: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); [UIView animateWithDuration:5.0 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }];}@end使用方法
[ShowToastView showToastView:self.view WithMessage:@"用户名或密码错误"];以上这篇IOS 仿Android吐司提示框的实例(分享)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了jQuery实现仿新浪微博浮动的消息提示框。分享给大家供大家参考。具体如下:这是一款jQuery实现的仿新浪微博新消息提示框效果,支持智能浮动定位
本文实例为大家分享了anadroid实现弹出提示框的具体代码,供大家参考,具体内容如下提示框是利用AlertDialog实现的。代码:(设置在button的点击
本文实例总结了Android开发中Toast显示消息的方法。分享给大家供大家参考,具体如下:Android中提供一种简单的Toast消息提示框机制,可以在用户点
本文实例讲述了Android编程中自定义dialog用法。分享给大家供大家参考,具体如下:dialog是android中提供的一组弹出提示框,非常好用,可是它的
本文实例为大家分享了Unity实现信息提示框的具体代码,供大家参考,具体内容如下1、创建一个信息提示框添加InfoTipsFrameScale脚本(然后将其制作