やり方
「Cocoa Touuch Class」を選択して「Next」を選択します。
Class: 任意のクラス名を設定
Subclass of: UINavigationController
を選択
作成したファイルに以下の記述をします
NavigationViewController.swift
import UIKit
class NavigationViewController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
navigationBar.barTintColor = UIColor(red: 85/255, green: 197/255, blue: 3/255, alpha: 255/255)
if #available(iOS 15.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .red
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
navigationBar.barTintColor = .red
}
}
}
デフォルトカラーにする
appearance.configureWithDefaultBackground()
色を選択する
appearance.backgroundColor = .red