通过UIWindow创建状态栏的通知
来源:互联网 发布:淘宝童鞋运动少女 编辑:程序博客网 时间:2024/06/05 10:54
//// 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 HQStatusBarHUDstatic 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
0 0
- 通过UIWindow创建状态栏的通知
- 创建状态栏通知 notification
- 简单创建Android状态栏通知
- Android 状态栏通知Notification的创建与使用
- StatusBar,状态栏 ,UIWindow
- 【notification】Android 中创建状态栏通知
- 创建UIWindow
- Android的状态栏通知(Notification)
- Android的状态栏通知(Notification)
- Android的状态栏通知(Notification)
- Android的状态栏通知(Notification)
- Android的状态栏通知(Notification)
- Android 的状态栏通知(Notification)
- 通过UIWindow的方法取消键盘
- iOS8中的UIScreen、UIWindow、键盘尺寸、状态栏尺寸的改动
- 安卓通知的使用系列2:状态栏通知和自定义状态栏通知通知
- UIWindow(控制器及view的创建)
- iOS中UIWindow的创建和删除
- 找出1到n所有不重复的排列,即n的全排列。
- poj 1064 Cable master
- 移动开发生态渐成
- Java进阶学习第十一天——cookie&session入门
- 随想2016
- 通过UIWindow创建状态栏的通知
- 60个有用CSS代码片段
- 1011 Problem K
- 关于无线传感器网络(WSN)的学术会议和期刊
- ActionServlet填充form的过程
- uploadFile2.php
- 正向代理与反向代理的区别(清晰明了)
- 【HUSTOJ】1056: 数字走向I
- Hadoop常见问题汇总-转载