通过自定义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里面也内置了弹出框组件.打开 ...
随机推荐
- mlpack:可伸缩C++机器学习库(转)
摘要:mlpack是一个可伸缩C++机器学习库,它的目的是让新用户通过简单.一致的API使用机器学习,同时为专业用户提供C++的高性能和最大灵活性. mlpack是一个直观.快速.可伸缩的C++机器学 ...
- J - 搞笑版费马大定理
J - 搞笑版费马大定理 Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu Submit ...
- BZOJ 1176: [Balkan2007]Mokia( CDQ分治 + 树状数组 )
考虑cdq分治, 对于[l, r)递归[l, m), [m, r); 然后计算[l, m)的操作对[m, r)中询问的影响就可以了. 具体就是差分答案+排序+离散化然后树状数组维护.操作数为M的话时间 ...
- 关于express4不再支持body-parser
express的bodyParser能将表单里的数据格式化,bodyParser原是绑定在express中的,但从express4开始,不在绑定了 如果依然直接使用app.use(express.bo ...
- codevs 1183 泥泞的道路 01分数规划
题目链接 题目描述 Description CS有n个小区,并且任意小区之间都有两条单向道路(a到b,b到a)相连.因为最近下了很多暴雨,很多道路都被淹了,不同的道路泥泞程度不同.小A经过对近期天气和 ...
- hdu 2824The Euler function
题目链接 快速求出a到b之间所有数的欧拉函数. 一个一个求肯定是不行的, 我们知道欧拉函数的公式为phi(n) = n*(1-1/i1)*(1-1/i2).......i1, i2为素因子. 那么我们 ...
- MySQL、You are using safe update mode
MySQL默认模式是sql_safe_updates=1的.在这个模式下不管你是update还是delete一行where 条件都要指定主键.如果where条件只出现的不是主键就会出错. 例子: se ...
- 美国vps哪个比较好,vps国内访问速度最快!
沃网中国是一家成立于2008年的国内idc商,提供基于hyper-v架构的VPS产品,数据中心包括国内电信.美国洛杉矶等,他们采用的是国内访问最快的加州机房ping值,160-180左右相当给力的速度 ...
- Codeforces 703D Mishka and Interesting sum(树状数组+扫描线)
[题目链接] http://codeforces.com/contest/703/problem/D [题目大意] 给出一个数列以及m个询问,每个询问要求求出[L,R]区间内出现次数为偶数的数的异或和 ...
- Orz 终于有了自己的博客地址
新博客地址:http://www.wnjxyk.cn/