通过UIWindow创建状态栏的通知
2016-05-05 21:21
453 查看
// // HQStatusBarHUD.m // StatusBarHUD // // Created by hq on 16/5/3. // Copyright © 2016年 hanqing. All rights reserved. // #import "HQStatusBarHUD.h" #define HQScreenWidth [UIScreen mainScreen].bounds.size.width //提示框的高度 #define HQTipsHeight 40 //字体大小 #define HQFontSize [UIFont systemFontOfSize:14] @interface HQStatusBarHUD() @end @implementation HQStatusBarHUD static UIWindow *window; static NSTimer *timer; +(void) setUpWindow{ window=[[UIWindow alloc] init]; window.windowLevel=UIWindowLevelStatusBar; window.frame=CGRectMake(0, -HQTipsHeight, HQScreenWidth,HQTipsHeight); window.hidden=NO; [UIView animateWithDuration:0.5 animations:^{ window.frame=CGRectMake(0,0, HQScreenWidth,HQTipsHeight); }]; } +(void) showMessage:(NSString *) message image:(UIImage *) image messageBgColor:(UIColor *)bgColor { [timer invalidate]; [self setUpWindow]; window.backgroundColor=bgColor; UIButton *but=[[UIButton alloc]initWithFrame:window.bounds]; but.titleEdgeInsets=UIEdgeInsetsMake(0, 10, 0, 0); [but setTitle:message forState:UIControlStateNormal]; [but setImage:image forState:UIControlStateNormal]; but.titleLabel.textColor=[UIColor whiteColor]; but.titleLabel.font=HQFontSize; [window addSubview:but]; //添加自动消失动画 timer=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(hide) userInfo:nil repeats:NO]; } //显示成功信息 +(void) showSuccessWithString:(NSString *) message{ [self showMessage:message image:[UIImage imageNamed:@"StatusBarHUD.bundle/success_ico"] messageBgColor:[UIColor colorWithRed:0.600 green:0.800 blue:0.400 alpha:1.000]]; } +(void) showErrorWithString:(NSString *) message{ [self showMessage:message image:[UIImage imageNamed:@"StatusBarHUD.bundle/error_icon"] messageBgColor:[UIColor colorWithRed:1.000 green:0.216 blue:0.246 alpha:1.000]]; } +(void) showMessageWithString:(NSString *) message{ [self showMessage:message image:[UIImage imageNamed:@"StatusBarHUD.bundle/info_icon"] messageBgColor:[UIColor colorWithRed:1.000 green:0.600 blue:0.000 alpha:1.000]]; } +(void)showLoading:(NSString *)message messageBgColor:(UIColor *)bgColor{ [self setUpWindow]; window.backgroundColor=bgColor; UIActivityIndicatorView *indicator=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; indicator.frame=CGRectMake(0, (HQTipsHeight-indicator.bounds.size.height)*0.5, indicator.bounds.size.width, indicator.bounds.size.height); [indicator startAnimating]; CGFloat labW=[message sizeWithAttributes:@{NSFontAttributeName:HQFontSize}].width; UILabel *lab=[[UILabel alloc]init]; lab.frame=CGRectMake(indicator.bounds.size.width, 0, labW, HQTipsHeight); lab.text=message; lab.textAlignment=NSTextAlignmentCenter; lab.textColor=[UIColor whiteColor]; lab.font=HQFontSize; UIView *view=[[UIView alloc] init]; view.bounds=CGRectMake(0, 0, indicator.bounds.size.width+labW, HQTipsHeight); view.center=window.center; [view addSubview:indicator]; [view addSubview:lab]; [window addSubview:view]; } +(void) showLoadingWithString:(NSString *) message{ [self showLoading:message messageBgColor:[UIColor colorWithRed:1.000 green:0.600 blue:0.000 alpha:1.000]]; } +(void) hide{ [UIView animateWithDuration:0.5 delay:0.5 options:UIViewAnimationOptionCurveLinear animations:^{ window.frame=CGRectMake(0,-HQTipsHeight, HQScreenWidth,HQTipsHeight); } completion:^(BOOL finished) { window=nil; }]; } @end
相关文章推荐
- HDOJ(HDU) 2192 MagicBuilding(用Java的Map做了下)
- HDOJ(HDU) 2192 MagicBuilding(用Java的Map做了下)
- leetcode_095 Unique Binary Search Trees II
- Android基础 | UI检视利器:Hierarchy Viewer
- String、StringBuffer与StringBuilder之间区别
- “java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp”
- tableviewcell自适应高度当中遇到添加label作为contentView,在实际显示时右侧出现空白
- njust 1925 sequence 拆分序列,寻找非降序列的最小个数,不变序列顺序。
- HDU 3836 Equivalent Sets
- HDU 2767 Proving Equivalences 增加最小边使图为强连通
- UIScrollView实现滑动图片
- requests 模拟登录百度
- easyUI获取当前行--代码
- UIScrollView实现缩放
- UIScrollView(滑动视图)
- -[UICachedDeviceRGBColor CGImage]: unrecognized selector sent to instance 0x130972b90
- UILabel 实现国际象棋棋盘界面
- APUE笔记:alarm和pause竞争
- UILabel 标签
- UILabel 实现计算器界面