直接上代码

#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吐司提示框的实例(分享)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

android自定义吐司通知,IOS 仿Android吐司提示框的实例(分享)相关推荐

  1. IOS 仿Android色轮代码

    IOS 仿Android色轮代码 在android中做色轮相对比较容易,因为Android中有一个角度渐变着色器函数SweepGradient能够很轻松的完成圆环的环形着色绘制工作,在利用Paint的 ...

  2. java数字时钟代码,Android自定义数字时钟代码,android自定义时钟,package jp.t

    Android自定义数字时钟代码,android自定义时钟,package jp.tpackage jp.tsmsogn.digitalclock;import java.util.Calendar; ...

  3. 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果

    原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...

  4. JS面向对象(仿邮箱登录提示框)

    最近在好好的研究JS,通过一个仿邮箱登录提示框的案例加深下对面向对象的理解!啥都别说,先上图: 功能:实现正则匹配显示相符的内容.键盘事件.鼠标事件 简单布局: <div id="lo ...

  5. Android手机teams,在iOS和Android上自定义Microsoft Teams体验的三种最佳方法

    以下是您可以在iOS和Android上自定义Microsoft Teams应用程序以使其成为自己的三种方法 1. 开启黑暗模式,以便iOS和Android上的小组中的消息和其他内容更易于理解和阅读 2 ...

  6. android自定义push通知_android通过自定义toast实现悬浮通知效果的示例代码

    android通过toast实现悬浮通知效果,如图: 实现的功能: 自定义悬浮弹窗: 点击其他地方该布局不受影响: 可自定义显示时间: 可以设置点击事件: 代码如下: import android.c ...

  7. android自定义push通知_Android自定义Notification的一些坑

    第一次在简书发文章,有问题多指教 本篇介绍自定义通知样式时会遇到的一些坑,本篇旨在记录坑,而不在全面讲解自定义的方法 坑 文字颜色:强烈使用系统定义的文字颜色,否则需要固定背景色 自定义View的尺寸 ...

  8. Android自定义记账软键盘(仿鲨鱼记账的记账功能)

    鲨鱼记账App效果: 本文实现的效果图: 本文 不是什么原理分析,属于使用工具,不再具体分析.直接贴图贴代码了 自定义软键盘的XML模版 注:android:codes的值,请参考ASCII < ...

  9. android 自定义特效,Android自定义View之高仿QQ健康

    我们都知道自定义View一般有三种直接继承View.继承原有的控件对控件的进行修改.重新拼装组合,最后一种主要针对于ViewGroup.具体的怎么做不是本文的所涉及的内容(本文是基于第一种方式实现的) ...

最新文章

  1. 【Qt】qss样式表之:自定义属性实现动态切换样式
  2. git客户端基本操作
  3. ant如何形成时间轴和图库_Python数据可视化常用4大绘图库原理详解_python
  4. ACL 2019 | 基于知识增强的语言表示模型,多项NLP任务表现超越BERT
  5. cython linux so,更改Cython的.so文件命名规则
  6. Zuul简介及代码示例
  7. IntelliJ IDEA for Mac在MacOS模式下的选择快捷键(Select Shortcut)
  8. 有没有词匹配算法_Google Ads 再次扩展了关键字变量匹配
  9. C#Socket同步异步通讯总结笔记
  10. 入门命令13-字符串查找增强:findstr
  11. Spark-SQL与hive整合【版本spark1.6.0+hive0.14】--Standalone模式
  12. 使用MyBatis后,DAO层的方法还能重载吗?
  13. 针式PKM的设计原则
  14. 蓝桥杯 回文数 C语言版
  15. 遇到网页无法复制文本怎么办,程序员来教你一键解锁,不需要任何软件和插件
  16. Entity Framework学习笔记——EF简介(一篇文章告诉你什么是EF)
  17. 九、路由原理与路由协议
  18. Python自动打码,DdddOcr通用验证码自动识别库
  19. 【电信学】【2018.01】在芬兰私人和公共停车场实施5G V2X服务
  20. NAXX Demo4_GZQ_04

热门文章

  1. PyTorch max()函数取最大值
  2. 人工智能成2020热搜专业,少儿编程未来可期!
  3. 【共振峰跟踪】通过平均不同分辨率的方法跟踪共振峰,基于时频lpc的频谱图的MATLAB仿真
  4. Nginx正则表达式之匹配操作符详解
  5. WPF最大化避免覆盖任务栏
  6. Count SIN Numbers
  7. Atitit 图像处理的心得与疑惑 attilax总结
  8. JavaWeb开发环境配置
  9. js中继承的几种用法总结(apply,call,prototype)
  10. 《降级论》《按时交作业的学生何以常穿脏袜子》读后感