Xcode 更改视图颜色后保留 NavigationBar 颜色

Xcode Keep NavigationBar Color after Change View Color

我正在使用 show segue 导航到这两个视图。 Profile 视图是 UIViewPreferences 视图是 UITableView。两者的属性相同

如何使导航栏在 Profile 视图中像在 Preferences 视图中一样保持灰色?

要更改背景颜色,我正在使用:

self.view.backgroundColor = UIColor.red

navigationBar默认是半透明的。
您需要明确禁用它以确保 navigationBar 是纯色,以防止背景颜色渗入其中。

self.navigationController?.navigationBar.isTranslucent = false