[英]iOS 7 UIStatusBarStyle Hide Status Bar During Application Launch Bug
我正在更新我的應用程序以將導航欄的顏色從白色更改為藍色。 因此,我想將狀態欄的顏色從黑色更改為白色。 我已經嘗試了Apple文檔中的所有內容,這有助於我在Storyboard中更改所有View控制器的狀態欄樣式。
但是,我推到的任何筆尖都不在我的故事板中,使用presentViewController會自動更改UIStatusBarStyle - 這是我的推送代碼:
NSString *url = @"https://twitter.com/Example";
NSString *title = @"Example";
SocialWebViewController *addController = [[[SocialWebViewController alloc] initWithURL:url title:title] initWithNibName:@"SocialWebView_iPhone" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
[self presentViewController:navigationController animated:YES completion:nil];
我已經在我的AppDelegate中放置了UIStatusBar首選樣式,這對我的StoryBoard中的ViewControllers起作用,但是只有:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
是的,我已經嘗試過了:
(1) [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
(2) [self setNeedsStatusBarAppearanceUpdate];
(3)在plist中將UIViewControllerBasedStatusBarAppearance設置為YES
沒有這個適用於那些不在我的StoryBoard中的筆尖。
好吧所以我想出你所說的是什么 - 設置查看基於控制器的狀態欄外觀“否”不是為我工作因為我的狀態欄在應用程序啟動期間一直隱藏,因為我在設置時一直隱藏它UIViewControllerBasedStatusBarAppearance為“NO”...我該如何解決這個問題?
在您的*-Info.plist
文件中設置鍵:
UIStatusBarStyle = UIStatusBarStyleLightContent
UIViewControllerBasedStatusBarAppearance = NO
UIStatusBarHidden = YES
在您的AppDelegate
將此行添加到方法application:didFinishLaunchingWithOptions
:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
如果你希望整個應用程序中的條形圖很輕,最簡單的方法是將UIViewControllerBasedStatusBarAppearance設置為NO然后再做
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
否則,只需在UIViewController中設置preferredStatusBarStyle即可,無需任何其他修改。
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
我懷疑你是使用UINavigationController / UITabBarController等來顯示UIViewController。 如果是這種情況,那么您將需要子類化UINavigationController / UITabBarController,以便添加正確的狀態欄樣式,您需要將這些控制器子類化以向其添加preferredStatusBarStyle方法。 這種事情的簡單實現如下
UINavigationControllerSubclass.h
#import <UIKit/UIKit.h>
@interface UINavigationControllerSubclass : UINavigationController
@end
UINavigationControllerSubclass.m
#import "UINavigationControllerSubclass.h"
@interface UINavigationControllerSubclass ()
@end
@implementation UINavigationControllerSubclass
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
@end
只需使用它而不是UINavigationController,狀態欄現在應該很輕。
在處理這種UI問題時,您總是需要考慮堆棧控制器。 由於UINavigationController包含UIViewController,如果您只在UIViewController中設置狀態欄屬性,UINavigationController不知道它並保留其原始屬性。 這就是為什么創建UINavigationController的子類並設置狀態欄樣式可以修復所有內容。 如果您遇到過這種問題,請盡量記住這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.