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 ...
随机推荐
- MySQL基础学习总结
1.MySQL基础概念 mysql逻辑架构如下: 每个客户端连接都会在服务器中拥有一个线程,这个连接的查询只会在这个单独的线程中执行. MySQL是分层的架构.上层是服务器层的服务和查询执行引擎,下层 ...
- 转载:JavaSE之反射
该文章转载自:http://www.cnblogs.com/rollenholt/archive/2011/09/02/2163758.html Java反射详解 本篇文章依旧采用小例子来说明,因为我 ...
- java 常见数据类型
int 4字节 -2 147 483 648-2 147 483 647(正好超过20亿) short 2字节 -32 768-32 767 long 8字节 -9 223 372 036 854 7 ...
- AC日记——组合数问题 落谷 P2822 noip2016day2T1
题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...
- strcmp()&&mb_ereg_replace()&&ereg()
主要记录两个函数,一个是strcmp(),一个是mb_ereg_replace() strcmp() php 5.3 以后字符串和数组比较会返回0 测试代码: PHP <?php $passwo ...
- noip模拟赛(10.4) 序列(sequence)
序列(sequence) [题目描述] 给定一个1~n的排列x,每次你可以将x1~xi翻转.你需要求出将序列变为升序的最小操作次数.有多组数据. [输入数据] 第一行一个整数t表示数据组数. 每组数据 ...
- 【点滴积累,厚积薄发】windows schedule task中.exe程序的路径问题等问题总结
1.在发布ReportMgmt的Job时遇到一个路径问题,代码如下: doc.Load(@"Configuration\Business\business.config"); ...
- Camera.Parameters 参数
public class Camera.Parameters extends Object java.lang.Object ↳ android.hardware.Camera.Paramete ...
- MVC UpdateModel的未能更新XXXXX的类型模型
关于MVC UpdateModel的未能更新XXXXX的类型模型 的问题: 最近做MVC3的项目,相信很多人都碰到过这个问题,在此记录一下,异常:UpdateModel的未能更新XXXXX的类型模型 ...
- MyBatis.Net 学习手记
MyBatis.NET的前身为IBatis,是JAVA版MyBatis在.NET平台上的翻版,相对NHibernate.EntityFramework等重量级ORM框架而言,MyBatis.NET必须 ...