LoginSignup
1
4

More than 3 years have passed since last update.

NavigatioBarとViewControllerに同じ色を設定したのに同じ色にならない時の解決法

Last updated at Posted at 2019-08-29

前提

self.view.backgroundColorself.navigationController?.navigationBar.barTintColorに同じ色を設定してあげるがnavigationBarが思った色にならない

原因

どうやらtranslucentという設定でNavigationBarが半透明になっているらしい

translucentとは

A Boolean value indicating whether the navigation bar is translucent (true) or not (false)

translucent(半透明)のそのままの意味でNavigationBarの半透明かどうかを表すProperty

・ナビゲーションバーにカスタムの背景画像がない場合、または背景画像のピクセルのアルファ値が1.0未満の場合、このプロパティのデフォルト値はtrueです。
・背景画像が完全に不透明な場合、このプロパティのデフォルト値はfalseです。

・このプロパティをtrueに設定し、カスタム背景画像が完全に不透明な場合、UIKitは画像に1.0未満のシステム定義の不透明度を適用します。
・このプロパティをfalseに設定し、背景画像が不透明でない場合、UIKitは不透明な背景を追加します。

Google翻訳より

自分の場合NavigationBarに背景画像を設定していなかったためtrueになってたみたいです

解決法

Xcode

スクリーンショット 2019-08-30 6.43.00.png

Transclucentのチェックを外してあげる

Code

self.navigationController?.navigationBar.isTranslucent = false

flaseにしてあげる

まとめ

備忘録として

参考リンク

translucent

1
4
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
1
4