Skip to content

Instantly share code, notes, and snippets.

@yosshi4486
Last active May 22, 2021 02:29
Show Gist options
  • Save yosshi4486/f196398b8a64d7f8402303766dc37874 to your computer and use it in GitHub Desktop.
Save yosshi4486/f196398b8a64d7f8402303766dc37874 to your computer and use it in GitHub Desktop.
viewWillAppearでこういうappearance設定を呼んであげると切り替えがうまくいく
extension UINavigationController {
/*
iOS13以降では、利用可能な場合はAppearance系API経由で見た目を設定するようにする。
 視覚情報と情報構造の切り分けを意識する。
*/
/// 不透明のNavigationBarを構成する
func configureOpaqueBar() {
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.shadowColor = .clear
navBarAppearance.shadowImage = UIImage()
navigationBar.standardAppearance = navBarAppearance
}
/// デフォルトのNavigationBarを構成する
func configureDefaultBar() {
let navBarAppreance = UINavigationBarAppearance()
navBarAppreance.configureWithDefaultBackground()
navigationBar.standardAppearance = navBarAppreance
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment