본문 바로가기

Swift

Status Bar 색상 지정

반응형

방법

두가지 방법이 있지만 첫번째 방법은 권장하지 않음

앱 전체에 대해 설정

  1. info.plist - View controller-based status bar appearance - NO
  2. AppDelegate 에 아래 코드 작성
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    application.statusBarStyle = .lightContent // .default
    return true
    }
    

각 뷰 컨트롤러에 대해 설정

  1. Defalut 는 No (그러나 위에서 info.plist를 건들였다면 를 View controller-based status bar appearance 없애거나 YES로 변경)
  2. 뷰 컨트롤러에 아래 코드 작성
    override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent // .default
    }
    

참고

preferredStatusBarStyle - UIViewController | Apple Developer Documentation

setStatusBarStyle(_:animated:) - UIApplication | Apple Developer Documentation

How to set Status Bar Style in Swift 3

반응형