重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要为大家展示了“IOS如何仿Android实现吐司提示框”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“IOS如何仿Android实现吐司提示框”这篇文章吧。
成都创新互联长期为上1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为兴隆企业提供专业的网站制作、成都做网站,兴隆网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。代码如下
#import@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实现吐司提示框”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联网站建设公司行业资讯频道!
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。