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

直接上代码

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

(0)

相关推荐

  • 高仿IOS的Android弹出框

    先看一下效果图,不过这是网上的图片. 效果不错,就借此拿来与大伙分享分享. github源码地址:https://github.com/saiwu-bigkoo/Android-AlertView. 1.怎么用:添加依赖. compile 'com.bigkoo:alertview:1.0.3' 2.实例demo(大家可以根据需要来选择自己需要的框框). package com.example.my.androidalertview; import android.app.Activity; i

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

    直接上代码 #import <UIKit/UIKit.h> @interface ShowToastView : UIView +(void)showToastView:(UIView *)uiview WithMessage:(NSString *)message; +(void)showToastViewShort:(UIView *)uiview WithMessage:(NSString *)message; +(void)showToastViewWithCostUpload:(UI

  • iOS中 LGLAlertView 提示框的实例代码

    使用与iOS8 以后,只是把系统的UIAlertController进行了封装,省的每次用的时候要写很多的代码.封装后只需要一句代码即可 , deome 地址 :https://github.com/liguoliangiOS/LGLAlertView.git 上代码LGLAlertView.h: #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger, LGLAlert

  • Android编程之自定义AlertDialog(退出提示框)用法实例

    本文实例讲述了Android编程自定义AlertDialog(退出提示框)用法,分享给大家供大家参考,具体如下: 有时候我们需要在游戏或应用中用一些符合我们样式的提示框(AlertDialog) 以下是我在开发一个小游戏中总结出来的.希望对大家有用. 先上效果图: 下面是用到的背景图或按钮的图片 经过查找资料和参考了一下例子后才知道,要实现这种效果很简单.就是在设置alertDialog的contentView. 以下的代码是写在Activity下的,代码如下: public boolean o

  • js实现仿阿里巴巴城市选择框效果实例

    本文实例讲述了js实现仿阿里巴巴城市选择框效果.分享给大家供大家参考.具体分析如下: 这并不是一个城市选择插件,在这里介绍只是为了mark一下二级联动的方法,此效果适用于有二级子菜单的效果,如导航栏.城市选择.类别选择等等. 样式效果是基于阿里的样式,懒得做其他调整,在area.css中仅仅是为了修改浏览器兼容性略做了一点调整. 城市数据是通过js构造,当然也可以通过后端取得数据,不过感觉没必要. <!doctype html> <html> <head> <me

  • Asp.Net中避免重复提交和弹出提示框的实例代码

    前台代码: <asp:Button ID="Button1" runat="server" Text="打印" onclick="Button1_Click" OnClientClick="this.value='数据提交中--';this.disabled=true;" UseSubmitBehavior="False" /> 后台代码: public partial cl

  • vue的全局提示框组件实例代码

    这篇文章给大家介绍一个vue全局提示框组件,具体代码如下所示: <template> <!-- 全局提示框 --> <div v-show="visible" class="dialog-tips dialog-center"> <div>{{message}}</div> </div> </template> <script> export default { data

  • php+ajax做仿百度搜索下拉自动提示框(有实例)

    php+mysql+ajax实现百度搜索下拉提示框 主要有3个文件三个文件在同一个目录里 如下图 下面是三个文件的代码 把sql文件导入到mysql数据库里 修改下数据库密码为自己的 记得哦是UTF-8编码 php+mysql+ajax实现百度搜索下拉提示框 效果图 rpc.php文件 复制代码 代码如下: <?php mysql_connect('localhost', 'root' ,''); mysql_select_db("test"); $queryString = $

  • jquery悬浮提示框完整实例

    本文实例讲述了jquery悬浮提示框实现方法.分享给大家供大家参考,具体如下: <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(function() { x = 5; y = 15; $("p").hover

  • 三种带箭头提示框总结实例

    无论是提示框还是导航栏都能看到如上图所示的带有箭头的框框,这种箭头可以通过背景图片或者是css来实现,本文介绍三种通过css实现带箭头的提示框. 1.通过border属性 思路:两个三角形,通过定位使两个三角形相差1px作为边框. 2.CSS3 transfrom 思路:先做一个两条边相同颜色的正方形,然后旋转一定角度就是三角形了 3.特殊字符'♦' 思路:特殊字符漏出上半部分,看上去就像三角形了 一.通过border属性: 我们先做一个宽和高都是10px的div,边框也是10px, width

  • 微信小程序 loading(加载中提示框)实例

    微信小程序 加载提示框: loading只有一个属性hidden .wxml <view> <loading hidden="{{hidden}}"> 加载中... </loading> <button bindtap="changeHidden">show/hidden</button> </view> .js Page({ data:{ hidden:true }, changeHidden

随机推荐