LoginSignup
0
2

More than 1 year has passed since last update.

【Swift】 UINavigationBar backgroud color

Posted at

UINavigationBarのカスタマイズについて
Xcode13&iOS15からNavigationBarがデフォルト透明になっている
(TabBarも同様)

navigationbarの設定は個別と全体設定がある
まず先にアプリの全体的なナビゲーション設定

UINavigationBarAppearance

インスタンスを作成しnavigationの設定ができます。

swift
init() {
    let appearance = UINavigationBarAppearance()
    // 設定内容
}

// 通常のナビゲーションバー
navigationItem.standardAppearance = appearance

// LargeTitle のナビゲーションバー
navigationItem.scrollEdgeAppearance = appearance

// Landscape のナビゲーションバー
navigationItem.compactAppearance = appearance


// 背景カスタマイズ
appearance.configureWithOpaqueBackground() 
appearance.titleTextAttributes = [.foregroundColor: UIColor.blue,.font : UIFont.systemFont(ofSize: 24)]




など

続いて個別設定の場合

swift
navigationController?.navigationBar.backgroundColor = .white

// IOS15未満で設定の場合は以下を追加
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)

詳しくはここ見る

0
2
0

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
0
2