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)
詳しくはここ見る