ios开发笔记--状态栏的自定义,隐藏
来源:互联网 发布:手提电脑mac地址怎么查 编辑:程序博客网 时间:2024/04/29 23:15
iOS7 StatusBar 在需要隐藏或改变样式时在UIViewConroller中调用:
- [self setNeedsStatusBarAppearanceUpdate];
1、隐藏
StatusBar在iOS7中无法使用一下接口隐藏:
- [[UIApplication sharedApplication] setStatusBarHidden:YES];
若要隐藏需要在UIViewController中实现下列函数:
- - (BOOL)prefersStatusBarHidden
- {
- return YES;
- }
2、样式改变
iOS 7中statusbar 有两种样式:白色字体UIStatusBarStyleLightContent和黑色字体UIStatusBarStyleDefault。
如果改变需要在UIViewController中实现:
- - (UIStatusBarStyle)preferredStatusBarStyle
- {
- return UIStatusBarStyleDefault;
- }
3、自定义状态栏,方法一
- UIWindow * statusWindow = [[UIWindow alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
- [statusWindow setWindowLevel:UIWindowLevelStatusBar + 1];
- [statusWindow setBackgroundColor:[UIColor clearColor]];
- UILabel * statusLabel = [[UILabel alloc] initWithFrame:statusWindow.bounds];
- statusLabel.text = @"RSSI:";
- statusLabel.textColor = [UIColor blueColor];
- statusLabel.textAlignment = NSTextAlignmentCenter;
- statusLabel.backgroundColor = [UIColor blackColor];
- [statusWindow addSubview:statusLabel];
- [statusWindow makeKeyAndVisible];
4、自定义状态栏,方法二
如果需要在状态栏显示自定义的消息时,就需要自定义状态栏。
代码如下:
XYCustomStatusBar.h
- #import <UIKit/UIKit.h>
- @interface XYCustomStatusBar : UIWindow{
- UILabel *_messageLabel;
- }
- - (void)showStatusMessage:(NSString *)message;
- - (void)hide;
- @end
XYCustomStatusBar.m
- #import "XYCustomStatusBar.h"
- @implementation XYCustomStatusBar
- - (void)dealloc{
- [super dealloc];
- [_messageLabel release], _messageLabel = nil;
- }
- - (id)init{
- self = [super init];
- if (self) {
- self.frame = [UIApplication sharedApplication].statusBarFrame;
- self.backgroundColor = [UIColor blackColor];
- self.windowLevel = UIWindowLevelStatusBar + 1.0f;
- _messageLabel = [[UILabel alloc] initWithFrame:self.bounds];
- [_messageLabel setTextColor:[UIColor whiteColor]];
- [_messageLabel setTextAlignment:NSTextAlignmentRight];
- [_messageLabel setBackgroundColor:[UIColor clearColor]];
- [self addSubview:_messageLabel];
- }
- return self;
- }
- - (void)showStatusMessage:(NSString *)message{
- self.hidden = NO;
- self.alpha = 1.0f;
- _messageLabel.text = @"";
- CGSize totalSize = self.frame.size;
- self.frame = (CGRect){ self.frame.origin, 0, totalSize.height };
- [UIView animateWithDuration:0.5 animations:^{
- self.frame = (CGRect){self.frame.origin, totalSize };
- } completion:^(BOOL finished){
- _messageLabel.text = message;
- }];
- }
- - (void)hide{
- self.alpha = 1.0f;
- [UIView animateWithDuration:0.5f animations:^{
- self.alpha = 0.0f;
- } completion:^(BOOL finished){
- _messageLabel.text = @"";
- self.hidden = YES;
- }];
- }
- @end
为了让自定义的状态栏可以让用户看到,设置了它的windowlevel,在ios中,windowlevel属性决定了UIWindow的显示层次,默认的windowlevel为UIWindowLevelNormal,即0.0 。为了能覆盖默认的状态栏,将windowlevel设置高点。其他代码基本上都不解释什么,如果要特殊效果,可以自己添加。
0 0
- ios开发笔记--状态栏的自定义,隐藏
- ios开发笔记--状态栏的自定义,隐藏
- ios开发笔记--状态栏的自定义,隐藏
- iOS开发笔记之隐藏状态栏UIStatusBar
- iOS开发隐藏状态栏
- ios开发 隐藏状态栏
- iOS开发 顶部状态栏的隐藏
- iOS开发:隐藏状态栏的方法
- iPhone开发笔记 退回输入键盘:自定义颜色:隐藏状态栏:
- iPhone开发笔记 退回输入键盘:自定义颜色:隐藏状态栏:
- iOS 状态栏的隐藏
- iOS 状态栏的隐藏
- 【iOS学习笔记】隐藏状态栏
- iOS 8开发隐藏状态栏
- 【iOS开发系列】隐藏状态栏
- ios开发之状态栏隐藏
- 自定义iOS的状态栏
- 自定义iOS的状态栏
- linux常用的五种查找指令
- 关于RelativeLayout常用属性
- 微信公众号的基础使用
- java提高篇(十四)-----关键字final
- leetcode274. H-Index
- ios开发笔记--状态栏的自定义,隐藏
- C语言循环数组做FIFO队列--一些认识
- 性能分析报告
- Xshell隐藏神技大揭密
- browserify和webpack
- ios开发笔记--委托机制详解及代码
- 设置当TextView中的文字超过TextView的容量时,用省略号代替
- Swift中文教程(十一) 方法
- 转:如何在Caffe中配置每一个层的结构