通过自定义window来实现提示框效果
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface ZMStatuBarHud : NSObject
//成功时候显示消息
+ (void)showSuccess:(NSString *)msg;
//失败的时候显示消息
+ (void)showError:(NSString *)msg;
//加载的时候显示 调用此方法想要隐藏需自己调用hide方法
+ (void)showLoading:(NSString *)msg;
//隐藏提示框
+ (void)hide;
//显示信息
+ (void)showMessage:(NSString *)msg;
//自定义提示框
+ (void)showMessage:(NSString *)msg image:(UIImage *)image;
@end
//
// ZMStatuBarHud.m
// 状态栏HUD232
//
// Created by 张明 on 16/3/7.
// Copyright © 2016年 张明. All rights reserved.
//
#define MMfont [UIFont systemFontOfSize:13]
#import "ZMStatuBarHud.h"
static UIWindow *window_;
static NSTimer *timer_;
//消息动画隐藏时间
static CGFloat const MMMessageDuration = 0.25;
@implementation ZMStatuBarHud
/*创建窗口*/
+ (void)setUpWindow
{
CGFloat windowH = 20;
CGRect frame = CGRectMake(0, -windowH, [UIScreen mainScreen].bounds.size.width, windowH);
window_.hidden = YES;
window_ = [[UIWindow alloc]init];
window_.frame = frame;
window_.hidden = NO;
window_.windowLevel = UIWindowLevelAlert;
window_.backgroundColor = [UIColor blackColor];
frame.origin.y = 0;
[UIView animateWithDuration:MMMessageDuration animations:^{
window_.frame = frame;
}];
}
+ (void)showMessage:(NSString *)msg image:(UIImage *)image
{
[timer_ invalidate];
//添加按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
[button setTitle:msg forState:UIControlStateNormal];
button.titleLabel.font = MMfont;
if (image) {
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
}
button.frame = window_.bounds;
[window_ addSubview:button];
timer_ = [NSTimer scheduledTimerWithTimeInterval:MMMessageDuration target:self selector:@selector(hide) userInfo:nil repeats:NO];
}
+ (void)hide
{
[UIView animateWithDuration:MMMessageDuration animations:^{
CGRect frame = window_.frame;
frame.origin.y = -frame.size.height;
window_.frame = frame;
} completion:^(BOOL finished) {
window_ = nil;
timer_ = nil;
}];
}
+ (void)showMessage:(NSString *)msg
{
[self showMessage:msg image:nil];
}
+ (void)showSuccess:(NSString *)msg
{
[self showMessage:msg image:[UIImage imageNamed:@"check"]];
}
+ (void)showError:(NSString *)msg
{
[self showMessage:msg image:[UIImage imageNamed:@"fault"]];
}
+ (void)showLoading:(NSString *)msg
{
[timer_ invalidate];
timer_ = nil;
[self setUpWindow];
UILabel *label = [[UILabel alloc]init];
label.font = MMfont;
label.frame = window_.bounds;
label.textAlignment = NSTextAlignmentCenter;
label.text = msg;
label.textColor = [UIColor whiteColor];
[window_ addSubview:label];
//加载圈圈
UIActivityIndicatorView *loadView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[loadView startAnimating];
CGFloat msgW = [msg sizeWithAttributes:@{NSFontAttributeName:MMfont}].width;
CGFloat centX = (window_.frame.size.width - msgW)*0.5 -20;
CGFloat centY = window_.frame.size.height*0.5;
loadView.center = CGPointMake(centX, centY)
;
[window_ addSubview:loadView];
}
@end
通过自定义window来实现提示框效果的更多相关文章
- 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
- JS组件Bootstrap实现弹出框和提示框效果代码
这篇文章主要介绍了JS组件Bootstrap实现弹出框和提示框效果代码,对弹出框和提示框感兴趣的小伙伴们可以参考一下 前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编 ...
- 单一按钮显示/隐藏&&提示框效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- WPF提示框效果
WPF提示框效果 1,新建WPF应用程序 2,添加用户控件Message 3,在Message中编写如下代码 <Border x:Name="border" BorderTh ...
- div+css实现圆形div以及带箭头提示框效果
.img{ width:90px; height:90px; border-radius:45px; margin:0 40%; border:solid rgb(100,100,100) 1px;& ...
- 基于JQuery 的消息提示框效果代码
提示框效果 一下是封装到 Jquery.L.Message.js 中的JS文件内容 var returnurl = ''; var messagebox_timer; $.fn.messagebox ...
- JS组件系列——Bootstrap寒冬暖身篇:弹出框和提示框效果以及代码展示
前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编辑功能,一般常见的主要有两种处理方式:行内编辑和弹出框编辑.在增加用户体验方面,弹出框和提示框起着重要的作用,如果你的 ...
- Bootstrap:弹出框和提示框效果以及代码展示
前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编辑功能,一般常见的主要有两种处理方式:行内编辑和弹出框编辑.在增加用户体验方面,弹出框和提示框起着重要的作用,如果你的 ...
- Bootstrap实现弹出框和提示框效果代码
一.Bootstrap弹出框使用过JQuery UI应该知道,它里面有一个dialog的弹出框组件,功能也很丰富.与jQuery UI的dialog类似,Bootstrap里面也内置了弹出框组件.打开 ...
随机推荐
- 浅谈Mybatis(三)
一.动态SQL 1.sql片段 解决sql语句的冗余代码问题. <sql id="SELECT_T_USER"> select id,name,password,bir ...
- 关于win7系统的Oracle安装时的[INS-30131]问题的解决方案
我是今天晚上安装的Oracle,结果在第二步遇到了这个问题,前后折腾了两个小时,百度了很多解决方案,终于解决了这个问题; 由于我的电脑系统还是win7的系统,其他的我没试过,不过也差不多都这么解决; ...
- csapp lab2 bomb 二进制炸弹《深入理解计算机系统》
bomb炸弹实验 首先对bomb这个文件进行反汇编,得到一个1000+的汇编程序,看的头大. phase_1: 0000000000400ef0 <phase_1>: 400ef0: 48 ...
- Hadoop学习之YARN框架
转自:http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/,非常感谢分享! 对于业界的大数据存储及分布式处理系统来说,H ...
- hadoop搭建杂记:Linux下不同linux主机之间文件copy的scp命令
不同的Linux之间copy文件常用有3种方法: 不同的Linux之间copy文件常用有3种方法: ①ftp 就是其中一台Linux安装ftp Server,这样可以另外一台使用ftp的程序来进行文件 ...
- 推荐一款手机端的图片滑动插件iSlider
首先先放出中文官方地址 http://be-fe.github.io/iSlider/index.html 这是demo 众所周知,移动端的图片滑动插件有很多,为什么我要推荐这个iSlider呢? ...
- Redhat Linux内核升级全记录(转)
http://www.sina.com.cn 2001/06/15 15:38 中国电脑教育报 李红 Redhat Linux因为比较容易上手,所以用户很多.它系统配置完善,预装了丰富的应 ...
- ssh 如何通过外网访问内网多台服务器
本帖子未验证: 我看到一个论坛,坛友发的一个问题 http://bbs.51cto.com/thread-934340-1.html 解决方法,我自己开了这个帖子写在这里. 首先你需要一个软件“Sec ...
- Android 新兴的UI模式——侧边导航栏【转】
侧边导航栏也就是大家熟知的SliddingMenu,英文也叫Fly-In App Menu.Side Navigation等.当然谷歌现在已经推出类似这个效果的组件--Navigation Drawe ...
- c语言中重要函数
gets函数,从标准输入读取一行文本,一行输入由一串字符组成,以一个换行符结尾: gets函数丢弃换行符,并在该行的末尾存储一个NUL字符(类似‘\0’), 然后返回一个非NULL值. 当gets函数 ...