我试图在导航栏上应用阴影,但是我所有的尝试都失败了。我找到了一个有效的解决方案,但它不能在ios 15....上工作谁能解决类似的问题,并分享一个可行的解决方案吗?
它不能在ios 15上运行:
navigationController?.navigationBar.layer.shadowColor = UIColor.baseGray.cgColor
navigationController?.navigationBar.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
navigationController?.navigationBar.layer.shadowRadius = 10.0
navigationController?.navigationBar.layer.shadowOpacity = 0.25
navigationController?.navigationBar.layer.masksToBounds = false
https://ibb.co/xsHh6wW
我找到了一个解决办法,也许有人会觉得有用
func setupShadowNavigationBar() {
if #available(iOS 15, *) {
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithDefaultBackground()
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().compactAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
}
navigationController?.navigationBar.layer.shadowColor = UIColor.baseGray.cgColor
navigationController?.navigationBar.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
navigationController?.navigationBar.layer.shadowRadius = 10.0
navigationController?.navigationBar.layer.shadowOpacity = 0.25
navigationController?.navigationBar.layer.masksToBounds = false
}