2014-03-07 72 views
2

我使用的是UINavigationControllerUIStatusBar在iOS7改變顏色

rootViewController,我做的導航欄,以透明

enter image description here

[self.view setBackgroundColor:[UIColor greenColor]]; 
self.navigationController.navigationBar.shadowImage = [UIImage new]; 
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; 

的問題是,當我瀏覽到第2的viewController

enter image description here

[self.navigationController.navigationBar setBackgroundColor:[UIColor greenColor]]; 

這裏我設置navigationBar顏色回綠色,但狀態欄沒有出現在綠色背景中。

是否有可能將狀態欄背景改爲綠色?

回答

2

寫的AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 

    // Override point for customization after application launch. 
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { 
     UIView *addStatusBar = [[UIView alloc] init]; 
     addStatusBar.frame = CGRectMake(0, 0, 320, 20); 
     //change this to match your navigation bar or view color or tool bar 
     //You can also use addStatusBar.backgroundColor = [UIColor BlueColor]; or any other color 
     addStatusBar.backgroundColor = [UIColor colorWithRed:0.973.0/255. green:0.973.0/255. blue:0.973.0/255. alpha:1]; 
     [self.window.rootViewController.view addSubview:addStatusBar]; 
    } 
    return YES; 
} 

的這didFinishLaunchingWithOptions方法,寫在其中設置狀態欄的背景顏色以下代碼。首先創建appdelegate的對象並使用該對象進行調用。

appdelegate.addStatusBar.backgroundColor = [UIColor colorWithRed:85.0/255.0 green:85.0/255.0 blue:85.0/255.0 alpha:1]; 

Refer this:

3
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)]; 

試試這個link