iOS不得姐项目--封装状态栏指示器(UIWindow实现)
一.头文件
#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实现)的更多相关文章
- iOS不得姐项目--TabBar的重复点击实现当前模块刷新;状态栏点击实现当前模块回滚到最顶部
一.实现功能:重复点击tabBar,刷新当前TableView,其余不受影响 <1>实现思路: 错误的方法: TabBar成为自己的代理,监听自己的点击--这种方法是不可取的,如果外面设置 ...
- iOS不得姐项目--appearance的妙用,再一次设置导航栏返回按钮,导航栏左右按钮的封装(巧用分类)
一.UI_APPEARANCE_SELECTOR 彩票项目中appearance的用法一直没有搞明白,这次通过第二个项目中老师的讲解,更深一层次的了解到了很多关于appearance的作用以及使用方法 ...
- iOS不得姐项目--pop框架的初次使用
一.pop和Core Animation的区别 1.Core Animation的动画只能添加到layer上 2.pop的动画能添加到任何对象 3.pop的底层并非基于Core Animation,是 ...
- iOS不得姐项目--精华模块上拉下拉的注意事项,日期显示,重构子控制器,计算cell的高度(只计算一次),图片帖子的显示
一.上拉下拉注意事项 使用MJRefresh中的上拉控件自动设置透明 当请求下页数据通过page的时候,注意的是上拉加载更多数据失败的问题,下拉加载数据失败了,页数应该还原.或者是请求成功的时候再将页 ...
- iOS不得姐项目--登录模块的布局,设置文本框占位文字颜色,自定义内部控件竖直排列的按钮
一.登录模块的布局 将一整部分切割成若干部分来完成,如图分成了三部分来完成 设置顶部状态栏为白色的方法 二.设置文本框占位文字颜色 <1>方法一与方法二实现原理是同一种,都是通过设置pla ...
- iOS不得姐项目--推荐关注模块(一个控制器控制两个tableView),数据重复请求的问题,分页数据的加载,上拉下拉刷新(MJRefresh)
一.推荐关注模块(一个控制器控制两个tableView) -- 数据的显示 刚开始加载数据值得注意的有以下几点 导航控制器会自动调整scrollView的contentInset,最好是取消系统的设置 ...
- iOS不得姐项目--图片帖子模块,大图默认显示最顶部分的处理
一.刚开始的处理,设置Mode属性(self.pictureImageView.contentMode = UIViewContentModeScaleAspectFill;) 和 Clip Subv ...
- iOS开发——UI精选OC篇&UIApplication,UIWindow,UIViewController,UIView(layer)简单介绍
UIApplication,UIWindow,UIViewController,UIView(layer)简单介绍 一:UIApplication:单例(关于单例后面的文章中会详细介绍,你现在只要知道 ...
- IOS客户端Coding项目记录导航
IOS客户端Coding项目记录(一) a:UITextField设置出现清除按键 b:绘画一条下划线 表格一些设置 c:可以定义表头跟底部视图(代码接上面) d:隐藏本页的导航栏 e:UIEdge ...
随机推荐
- 深入理解FTP协议
文件传输协议FTP(File Transfer Protocol)是因特网中使用最广泛的文件传输协议.FTP使用交互式的访问,允许客户指定文件的类型和格式(如指明是否使用ASCII码),并允许文件具有 ...
- 【CSS】使用CSS选择器
CCS选择器的作用是找出某类元素.以便使我们使用style元素或者外部样式表对这类元素设置样式. 1.使用CSS基本选择器 有些选择器使用起来非常简单,我们把这部分选择器称为基本选择器(basic s ...
- AC日记——刺激 codevs 1958
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description saffah的一个朋友S酷爱滑雪,并且追求刺激(exitement,由于刺激 ...
- javascript高级程序设计 读书笔记2
第五章 引用类型 对象是引用类型的实例,引用类型是一种数据结构,将数据和功能组织在一起.描述的是一类对象所具有的属性和方法.对象是某个特定引用类型的实例,新对象是使用new操作符后跟一个构造函数俩创建 ...
- 基于jquery的tips悬浮消息提示插件tipso
<a href="javascript:;" class="disabled" data-tipso="Tips" id=" ...
- crontab日常使用梳理
在日常的运维工作中,对crontab定时任务的制定是再寻常不过的了.根据以往的使用经验梳理如下: 基本格式 :* * * * * command分 时 日 月 周 命令解释:第1列表示分钟1-59 每 ...
- Elasticsearch-2.3.x填坑之路
使用版本说明:2.3.2 强制不能使用root用户启动?因为在2.x版本强调了安全性,防止attracker侵入root用户,所以建议使用者创建其他用户启动.当然,可以通过配置来实现root用户启动. ...
- 简易安装python统计包
PythonCharm简易安装python统计包及 本文介绍使用pythonCharm IDE 来安装Python统计包或一些packages的简单过程,基本无任何技术难度,顺便提一提笔者在安装过程中 ...
- pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat Windows7下pip安装包报错:Microso ...
- 在GoF设计模式
在GoF设计模式中,结构型模式有: 1.适配器模式 Adapter 适配器模式是将一个类的接口转换成客户希望的另外一个接口.适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. ...