回答

1

此方法添加到您的每一個視圖控制器,或者(在類中的方法調用它)

-(void)status_bar_color 
{ 
     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) 
     { 
      UIView *addStatusBar = [[UIView alloc] init]; 
      CGSize result = [[UIScreen mainScreen] bounds].size; 
      if(result.height >750) 
      { 
        addStatusBar.frame = CGRectMake(0, 0, 800, 23); 
      } 
      else if(result.height >550)//IPod 
      { 
        addStatusBar.frame = CGRectMake(0, 0, 320, 23); 
      } 
      else 
      { 
        addStatusBar.frame = CGRectMake(0, 0, 320, 23); 
      } 

      addStatusBar.backgroundColor=[UIColor blackColor]; 
      [self.view addSubview:addStatusBar]; 
     } 
} 

對於狀態欄的輕質成分,使用這種方法也

-(UIStatusBarStyle)preferredStatusBarStyle 
{ 
     return UIStatusBarStyleLightContent; 
} 

酷..

+0

這是不好的,RootVc導航是隱藏的添加子視圖是好的,但PushVc不好 –

+0

我有沒有辦法改變它爲pushvc?在我的項目中,我選擇了所有視圖控制器作爲模型,因此適合我。 –

+0

我很抱歉...我在didReceiveMemoryWarning中調用了這個方法....不小心 –

0

View controller-based status bar appearanceNO。從項目設置您可以更改狀態欄背景顏色按您的要求的項目info.plist.and

我有一個建議,請更改窗口背景色,並設置狀態欄UIStatusBarStyleBlackTranslucent 添加以下代碼appdelegate.m:

self.window.backgroundColor = [UIColor <yourColor>]; 
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; 
+0

我沒有找到修改狀態欄的顏色屬性 –

+0

ohh對不起,你的意思是你想要狀態欄BG的顏色除了淺灰色和黑色顏色?如果是的話請看我編輯的答案 –

+0

我已經得到了答案〜非常感謝你的回答〜 –

0

這是我用來更改狀態欄顏色或背景的代碼。

 if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) 
     { 
      UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)]; 
    view.backgroundColor=[UIColor YourColorName]; 

If you wanted to add image you can use the line given below. 
/* 
      view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"loginbackground.png"]]; 
      [self.view addSubview:view]; 
*/   
} 

試試這個如果我不工作,請讓我知道。

相關問題