1.statusBar Info.plist文件配置說明詳
分別在 Info.plist中添加以下字段,分別表示
1.Status bar is initially hidden 在程序啟動過程中是否隱藏狀態(tài)欄 需要隱藏 YES 不隱藏 NO鸳谜。
2.View controller-based status bar appearance 全局statusbar默認(rèn)樣式列敲,這個可以這樣理解 當(dāng)設(shè)置為YES是全局樣式統(tǒng)一弄企,只可通過- (BOOL)prefersStatusBarHidden 寒跳,進(jìn)行隱藏設(shè)置 硕淑,默認(rèn)黑色字體胚委,可編輯性較差挟鸠,所以此處一般設(shè)為NO。
3.Status bar style 字體顏色設(shè)置
typedef NS_ENUM(NSInteger, UIStatusBarStyle) {
UIStatusBarStyleDefault = 0, // Dark content, for use on light backgrounds
UIStatusBarStyleLightContent NS_ENUM_AVAILABLE_IOS(7_0) = 1, // Light content, for use on dark backgrounds
UIStatusBarStyleBlackTranslucent NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 1,
UIStatusBarStyleBlackOpaque NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 2,
} __TVOS_PROHIBITED;
由此我們可以看出Status bar style 提供四個接口參數(shù)篷扩,其中UIStatusBarStyleBlackTranslucent 兄猩,UIStatusBarStyleBlackOpaque iOS7之后已經(jīng)廢棄,我們常用的UIStatusBarStyleDefault 黑色字體 UIStatusBarStyleLightContent 白色字體兩種
如圖:info.png
2.自定義狀態(tài)欄背景顏色
效果如下:背景顏色.png
代碼如下:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
//在將要顯現(xiàn)頁面時進(jìn)行鉴未,顏色設(shè)置
[self setStatusBarBackgroundColor:[UIColor blueColor]];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:YES];
//在頁面將要離開事對設(shè)置顏色進(jìn)行置空恢復(fù)原來的顏色枢冤,或者clearColor 在此之前打印其背景顏色你會發(fā)現(xiàn)是空的。
[self setStatusBarBackgroundColor:NULL];
}
//設(shè)置狀態(tài)欄顏色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
3.隱藏設(shè)置 及動畫
一切盡在無言中
- (IBAction)show:(id)sender {
[UIView animateWithDuration:1.0 animations:^{
// typedef NS_ENUM(NSInteger, UIStatusBarAnimation) {
// UIStatusBarAnimationNone,無動畫效果
// UIStatusBarAnimationFade,顏色漸變效果動畫
// UIStatusBarAnimationSlide,滑動動畫
// } __TVOS_PROHIBITED;
//直接出現(xiàn)
//[[UIApplication sharedApplication] setStatusBarHidden:NO];
//顏色漸漸變深直到出現(xiàn)
//[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:YES];
//顏色漸漸變深直到出現(xiàn)
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}];
}
- (IBAction)hide:(id)sender {
[UIView animateWithDuration:1.0 animations:^{
//直接消失
//[[UIApplication sharedApplication] setStatusBarHidden:NO];
//顏色漸漸變淺直到消失
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
}];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:YES];
//在頁面將要離開事對設(shè)置顏色進(jìn)行置空恢復(fù)原來的顏色铜秆,或者clearColor 在此之前打印其背景顏色你會發(fā)現(xiàn)是空的淹真。
[self setStatusBarBackgroundColor:NULL];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}