2014-06-30 56 views
0

導航欄和狀態欄的問題,我已經爲iOS7之前創建的使用XIB的應用程序而不Status Bar,現在我需要在我的應用程序添加Status barStatus bar background color應該一樣Navigation bar背景顏色。這就是我一直喜歡(在我的info.plist):在iOS的7

1) Set View controller-based status bar appearance to NO 
2) Set Status bar style to UIStatusBarStyleLightContent 

這裏是我的App Delegate代碼:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; 

[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault]; 
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]]; 
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]]; 

所以我得到的輸出像下面的圖片:

enter image description here

我還得到了錯誤的UIButtons,我在屏幕下方給出了它(它隱藏了20個像素)。

你能幫我,我該如何解決這個問題?我需要我的輸出像下面的圖片:

enter image description here

任何幫助將非常感激,謝謝。

第三個屏幕:在您的viewDidLoad方法

enter image description here

+0

您正在裁剪並且邊界的origin.y爲20px。這似乎是問題所在? – aforaudrey

+0

@DanqingThanks,你能告訴我我需要做什麼改變嗎? – user2786

+0

爲什麼給窗口y座標爲20? –

回答

1

添加以下代碼:

float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; 

if (systemVersion >= 7.0) 
{ 
    self.edgesForExtendedLayout = UIRectEdgeNone; 
} 
+0

Mallesh MaddaliI在我的viewDidLoad方法中添加了相同的內容,但仍然獲得與圖像1相同的輸出。如何區分狀態欄和導航欄? – user2786

+0

嘗試從AppDelegate中刪除以下代碼:[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; –

+0

謝謝@Naga我已經刪除提到的線..現在我得到沒有狀態欄的輸出。 – user2786

0

驚喜在人們很少有提出這一點。這裏是(無盜號)

首先,讓你的導航欄有20

一個Y原點然後在.h文件中,設置您的ViewController爲UIBarPositioningDelegate正確的方法:

@interface XYZViewController : UIViewController <UIBarPositioningDelegate> 

而在.m文件:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.navigationBar.delegate = self; 
} 

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar { 
    return UIBarPositionTopAttached; 
} 
1

請AppDelegate.h定義這個(或)constants.h

#define isIOS7 ([[[UIDevice currentDevice]systemVersion]floatValue] >=7.0)?YES:NO 

under viewDidLoad撰寫這一句。

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { 
    UIView *addStatusBar = [[UIView alloc] init]; 
    addStatusBar.frame = CGRectMake(0, 0, 320, 20); 
    addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1]; 


    //change this to match your navigation bar 
    [self.window.rootViewController.view addSubview:addStatusBar]; 
    } 

或者我們可以在xib中手動更改它。

通過將每個元素向下移動20px。

Seethis image