LoginSignup
2
5

More than 1 year has passed since last update.

iOS15で透明になってしまったStatusBarとNavigationBarに色をつける

Last updated at Posted at 2021-10-03

はじめに

以前作ったアプリをXcode13.0でビルドするとiOS15.0でStatusBarとNavigatoinBarが透明に
なってしまったため、色をつけるコードを追加した忘備録。

環境

Xcode Version 13.0 (13A233)

※StoryBoardは使わずコードのみでViewを作ったアプリです。

状況

StatusBar,NavigationBarがiOS15で透明になってしまう。

スクリーンショット 2021-10-03 14.20.46.png

手順

1.AppDelegateのdidFinishLaunchingWithOptionsにコードを追記

AppDelegate.swift

var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        //★★バーの色を変更するコードを追記する
        if #available(iOS 15.0, *) {
            let appearace = UINavigationBarAppearance()
            appearace.backgroundColor = .lightGray
            UINavigationBar.appearance().scrollEdgeAppearance = appearace

        }
        //★★ここまで 

        //元々自分で追記していた、rootViewControllerを表示するコード
        let window = UIWindow(frame: UIScreen.main.bounds)
        self.window = window
        window.makeKeyAndVisible()
        window.rootViewController = UINavigationController(rootViewController: ViewController())

        return true
    }

2.結果

BarがLightGray色になった。

スクリーンショット 2021-10-03 14.35.45.png

最後に

間違いなどありましたらご指摘いただけると幸いです。

2
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5