一.头文件

 #import <UIKit/UIKit.h>

 @interface ChaosStatusBarHUD : NSObject
/** 显示成功信息 */
+ (void)showSuccess:(NSString *)str;
/** 显示失败信息 */
+ (void)showError:(NSString *)str;
/** 显示正在加载的信息 */
+ (void)showLoading:(NSString *)str;
/** 隐藏 */
+ (void)hide;
/** 显示纯文本 */
+ (void)showMessage:(NSString *)str;
/** 自定义图标 文字 */
+ (void)showMessage:(NSString *)str withImage:(UIImage *)image;
@end

二.实现.m文件

 #import "ChaosStatusBarHUD.h"

 #define ChaosWindowH 20
#define ChaosScreenW [UIScreen mainScreen].bounds.size.width @implementation ChaosStatusBarHUD static NSTimer *timer_;
static UIWindow *window_; + (void)showWindow
{
// 首先结束之前的定时器
[timer_ invalidate];
UIWindow *window = [[UIWindow alloc] init];
window.backgroundColor = [UIColor blackColor];
window.windowLevel = UIWindowLevelStatusBar;
window.hidden = NO;
window_ = window;
window.frame = CGRectMake(, -ChaosWindowH, ChaosScreenW, ChaosWindowH); // 动画效果
[UIView animateWithDuration:0.25 animations:^{ window.frame = CGRectMake(, , ChaosScreenW, ChaosWindowH);
}];
}
/** 自定义图标 文字 */
+ (void)showMessage:(NSString *)str withImage:(UIImage *)image
{
// 创建窗体
[self showWindow];
// 添加按钮
UIButton *button = [[UIButton alloc] init];
button.frame = window_.bounds;
[button setImage:image forState:UIControlStateNormal];
[button setTitle:str forState:UIControlStateNormal];
button.titleEdgeInsets = UIEdgeInsetsMake(, , , );
button.titleLabel.font = [UIFont systemFontOfSize:];
[window_ addSubview:button]; // 两秒后结束动画
timer_ = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hide) userInfo:nil repeats:NO];
} /** 显示纯文本 */
+ (void)showMessage:(NSString *)str
{
[self showMessage:str withImage:nil];
} /** 显示成功信息 */
+ (void)showSuccess:(NSString *)str
{
[self showMessage:str withImage:[UIImage imageNamed:@"success"]];
} /** 显示失败信息 */
+ (void)showError:(NSString *)str
{
[self showMessage:str withImage:[UIImage imageNamed:@"error"]];
} /** 显示正在加载的信息 */
+ (void)showLoading:(NSString *)str
{
// 停止定时器
[timer_ invalidate];
timer_ = nil;
// 创建窗口
[self showWindow];
// 添加按钮
UIButton *button = [[UIButton alloc] init];
button.frame = window_.bounds;
[button setTitle:str forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:];
[window_ addSubview:button];
// 计算按钮文字宽度
CGFloat titleWidth = [str sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:]}].width;
// 计算菊花的X值
CGFloat x = (ChaosScreenW - * titleWidth) * 0.5;
// 计算loadingView的Y值
CGFloat y = window_.frame.size.height * 0.5;
UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[loadingView startAnimating];
[window_ addSubview:loadingView];
loadingView.center = CGPointMake(x, y);
} /** 隐藏 */
+ (void)hide
{
// 动画效果
[UIView animateWithDuration:0.25 animations:^{ window_.frame = CGRectMake(, -, ChaosScreenW, ChaosWindowH);
} completion:^(BOOL finished) { timer_ = nil;
window_ = nil;
}];
}
@end

iOS不得姐项目--封装状态栏指示器(UIWindow实现)的更多相关文章

  1. iOS不得姐项目--TabBar的重复点击实现当前模块刷新;状态栏点击实现当前模块回滚到最顶部

    一.实现功能:重复点击tabBar,刷新当前TableView,其余不受影响 <1>实现思路: 错误的方法: TabBar成为自己的代理,监听自己的点击--这种方法是不可取的,如果外面设置 ...

  2. iOS不得姐项目--appearance的妙用,再一次设置导航栏返回按钮,导航栏左右按钮的封装(巧用分类)

    一.UI_APPEARANCE_SELECTOR 彩票项目中appearance的用法一直没有搞明白,这次通过第二个项目中老师的讲解,更深一层次的了解到了很多关于appearance的作用以及使用方法 ...

  3. iOS不得姐项目--pop框架的初次使用

    一.pop和Core Animation的区别 1.Core Animation的动画只能添加到layer上 2.pop的动画能添加到任何对象 3.pop的底层并非基于Core Animation,是 ...

  4. iOS不得姐项目--精华模块上拉下拉的注意事项,日期显示,重构子控制器,计算cell的高度(只计算一次),图片帖子的显示

    一.上拉下拉注意事项 使用MJRefresh中的上拉控件自动设置透明 当请求下页数据通过page的时候,注意的是上拉加载更多数据失败的问题,下拉加载数据失败了,页数应该还原.或者是请求成功的时候再将页 ...

  5. iOS不得姐项目--登录模块的布局,设置文本框占位文字颜色,自定义内部控件竖直排列的按钮

    一.登录模块的布局 将一整部分切割成若干部分来完成,如图分成了三部分来完成 设置顶部状态栏为白色的方法 二.设置文本框占位文字颜色 <1>方法一与方法二实现原理是同一种,都是通过设置pla ...

  6. iOS不得姐项目--推荐关注模块(一个控制器控制两个tableView),数据重复请求的问题,分页数据的加载,上拉下拉刷新(MJRefresh)

    一.推荐关注模块(一个控制器控制两个tableView) -- 数据的显示 刚开始加载数据值得注意的有以下几点 导航控制器会自动调整scrollView的contentInset,最好是取消系统的设置 ...

  7. iOS不得姐项目--图片帖子模块,大图默认显示最顶部分的处理

    一.刚开始的处理,设置Mode属性(self.pictureImageView.contentMode = UIViewContentModeScaleAspectFill;) 和 Clip Subv ...

  8. iOS开发——UI精选OC篇&UIApplication,UIWindow,UIViewController,UIView(layer)简单介绍

    UIApplication,UIWindow,UIViewController,UIView(layer)简单介绍 一:UIApplication:单例(关于单例后面的文章中会详细介绍,你现在只要知道 ...

  9. IOS客户端Coding项目记录导航

    IOS客户端Coding项目记录(一) a:UITextField设置出现清除按键 b:绘画一条下划线  表格一些设置 c:可以定义表头跟底部视图(代码接上面) d:隐藏本页的导航栏 e:UIEdge ...

随机推荐

  1. [Top-Down Approach] Assignment 1: WebServer [Python]

    Today I complete Socket Programming Assignment 1 Web Server Here is the code: #!/usr/bin/python2.7 # ...

  2. Use getopt() & getopt_long() to Parse Arguments

    Today I came across a function [getopt] by accident. It is very useful to parse command-line argumen ...

  3. ExtJs4 笔记(14) layout 布局

    作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...

  4. AC日记——有趣的跳跃 openjudge 1.6 07

    07:有趣的跳跃 总时间限制:  1000ms 内存限制:  65536kB 描述 一个长度为n(n>0)的序列中存在“有趣的跳跃”当前仅当相邻元素的差的绝对值经过排序后正好是从1到(n-1). ...

  5. VS设置程序集属性(文件的详细信息)

    适用范围 本文方法适用于:C#创建的控制台程序,WinForm,WPF等VS创建的.Net工程信息设置. 方法步骤 1.在 项目 上点击鼠标右键选择 属性 ,进入这个页面,点击 程序集信息(重点关注 ...

  6. UI坐标变换/转换

    InverseTransformPoint Transform.InverseTransformPoint :相对于谁的坐标.如果是相对2D UI,请使用localposition,如果是3D场景,请 ...

  7. JVM的垃圾回收机制详解和调优

    JVM的垃圾回收机制详解和调优 gc即垃圾收集机制是指jvm用于释放那些不再使用的对象所占用的内存.java语言并不要求jvm有gc,也没有规定gc如何工作.不过常用的jvm都有gc,而且大多数gc都 ...

  8. luogu1003铺地毯[noip2011 提高组 Day1 T1]

    题目描述 为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有 n 张地毯,编号从 1 到n .现在将这些地毯按照编号从小到大的顺序平行于 ...

  9. 利用统计学知识为android应用的启动时间做数据分析

    [声明:如需转载本文,请注明来源] 一.数据说明 启动时间用同一台设备,同一个包进行启动时间的测试,其中三组样本数据(每组100份对比数据)如下: 设备pro-5-1 base_list_1 = [0 ...

  10. Activity 与 Service 之间的消息传递

    BgService代码 public class BgService extends Service { public static final String TAG = "BgServic ...