[英]Changing Color of the Navigation Bar's Safe Area Swift UIKit
I am running into an issue.我遇到了一个问题。 I want the whole navigation bar (including safe area) color to change but the safe area color doesnt change at all (no matter what changes I make to it).
我希望整个导航栏(包括安全区域)的颜色发生变化,但安全区域的颜色根本没有变化(无论我对其进行了何种更改)。
Heres继承人
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.backgroundColor = .green
navigationItem.titleView = searchBar
I even tried changing the Nav Bar's:我什至尝试更改导航栏的:
with no luck.没有运气。
Current Navigation Bar Color当前导航栏颜色
This view controller is being presented from the Scene Delegate using a navigation controller.这个视图 controller 正在使用导航 controller 从场景代理中呈现。
Let me know if you need any additional information.如果您需要任何其他信息,请告诉我。
Try this in your SceneDelegate在您的 SceneDelegate 中试试这个
if #available(iOS 15, *) {
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithOpaqueBackground()
navigationBarAppearance.titleTextAttributes = [
NSAttributedString.Key.foregroundColor : UIColor.white
]
navigationBarAppearance.shadowColor = nil
navigationBarAppearance.backgroundColor = .green
UINavigationBar.appearance().barStyle = .green
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().compactAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
}
Found a solution:找到解决方案:
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .green
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
navigationItem.titleView = searchBar
I entered this in the function where I was configuring the navigation bar我在配置导航栏的 function 输入这个
Credit: https://developer.apple.com/forums/thread/682420学分: https://developer.apple.com/forums/thread/682420
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.