热门标签 | HotTags
当前位置:  开发笔记 > Android > 正文

IOS仿Android吐司提示框的实例(分享)

下面小编就为大家分享一篇IOS仿Android吐司提示框的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

直接上代码

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


推荐阅读
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 安卓select模态框样式改变_微软Office风格的多端(Web、安卓、iOS)组件库——Fabric UI...
    介绍FabricUI是微软开源的一套Office风格的多端组件库,共有三套针对性的组件,分别适用于web、android以及iOS,Fab ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • Android中高级面试必知必会,积累总结
    本文介绍了Android中高级面试的必知必会内容,并总结了相关经验。文章指出,如今的Android市场对开发人员的要求更高,需要更专业的人才。同时,文章还给出了针对Android岗位的职责和要求,并提供了简历突出的建议。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
author-avatar
顺佳海外
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有