通过自定义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里面也内置了弹出框组件.打开 ...
随机推荐
- cocos2d-X-3.X 场景与层
1场景与层的相关函数 1. void runWithScene(Scene * scene). 该函数可以运行场景.只能在启动第一个场景时调用该函数.如果已经有一个场景运行,则不能调用该函数. 2. ...
- halcon与C#混合编程进阶版
这篇主要是C#和Halcon的混合编程,在此基础上对按键不同功能的划分,以及图片适应窗口和从本地打开图片. 新手来这里:http://www.cnblogs.com/badguy518/p/55150 ...
- 四轴飞行器1.2.3 STM32F407时钟配置和升级标准库文件
原创文章,欢迎转载,转载请注明出处 这个星期进度比较慢哈,只有周末和晚上下班回来才能做,事件不连续,琐碎的事情又比较多,挺烦的,有多琐碎呢? 1.本人有点小强迫症哈,虽然RTT将文 ...
- 服务器是R710常见错误汇总:
报错: E1422 CPU 1 machine check error . power cycle AC 解决方案: 系统 BIOS 已报告机器检查错误.请断开系统的交流电源 10 秒,然后重新启动系 ...
- 【高级】C++中虚函数机制的实现原理
多态是C++中的一个重要特性,而虚函数却是实现多态的基石.所谓多态,就是基类的引用或者指针可以根据其实际指向的子类类型而表现出不同的功能.这篇文章讨论这种功能的实现原理,注意这里并不以某个具体的编译器 ...
- HDU 2167 Pebbles
题目大意:有个N*N( 3<=N<=15 )方阵, 可从中若干个数, 使其总和最大.取数要求, 当某一个数被选, 其周围8个数都不能选. 题解:记s数组为合法状态,即没有相邻的数字同时被选 ...
- VS2010/MFC对话框:文件对话框
文件对话框 上一讲介绍的是消息对话框,本节讲解文件对话框.文件对话框也是很常用的一类对话框. 文件对话框的分类 文件对话框分为打开文件对话框和保存文件对话框,相信大家在Windows系统中 ...
- SDWebImage缓存
缓存图片方法 [[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey]; 读取缓存 UIImage *myCache ...
- Android 动画animation 深入分析
转载请注明出处:http://blog.csdn.net/farmer_cc/article/details/18259117 Android 动画animation 深入分析 前言:本文试图通过分析 ...
- iOS解析数据判断nil NULL Null的方法
+ (BOOL)isNil:(NSObject*)obj { if (obj == nil || obj == NULL) { return YES; } if ([obj isKindOfClass ...