Skip to content

IOS:StatusBar

The status bar displays important information about the device and the current environment (shown below on iPhone).

Status Bar Black Error

아래의 그림과 같이 상태바(StatusBar)가 검은색으로 출력되었을 경우 해결할 수 있는 방법에 대하여 정리한다.

Ios7_statusbar_error_sample.png

iOS7 StatusBar Style

IOS7로 업데이트되면서 우리가 제어할 수 있는게 몇가지 늘어났는데 이중 하나가 StatusBar입니다. UIViewController에 아래와 같이 정의되어 있다.

// These methods control the attributes of the status bar when this view controller is shown. They can be overridden in view controller subclasses to return the desired status bar attributes.
- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0); // Defaults to UIStatusBarStyleDefault

이 함수를 아래와 같이 재정의(Override)하면 된다.

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

iOS7 StatusBar 겹침 현상

iOS 버전 업데이트와 동시에 6, 7 버전의 차이로 인해 상태바의 위치가 변경됨. 기존 6버전 에서는 20px만큼의 고정된 영역을 차지하던 상태바가, 7버전에서는 고정된 영역이 아닌 겹쳐지는 영역을 사용하는 방식으로 바뀐듯. 해결 방법으로, AppDelegatedidFinishLaunchingWithOptions함수에 아래와 같은 내용을 추가하면 된다.

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    // [application setStatusBarStyle:UIStatusBarStyleLightContent];
    self.window.clipsToBounds = YES;
    self.window.frame =  CGRectMake(0, 20, self.window.frame.size.width,self.window.frame.size.height - 20);
    self.window.bounds = CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height);
}

또는 아래와 같이 간단하게 해결할 수 있다.

CGRect frame = self.navigationController.view.frame;
frame.origin.y = 20;
self.navigationController.view.frame = frame;

Favorite site

Technical Q&A: iOS7 StatusBar

iOS7 StatusBar 관련 이슈

References


  1. Iphone_-iOS_7_status_bar_back_to_iOS_6_style's_issue-_Stack_Overflow.pdf 

  2. Statusbar_-iOS_7_status_bar_back_to_iOS_6_style-_Stack_Overflow.pdf 

  3. Ios_-Status_bar_and_navigation_bar_issue_in_IOS7-_Stack_Overflow.pdf 

  4. IOS7_-_StatusBar_and_CustomNavigation.pdf