首页 > 解决方案 > Swift UINavigation 底线和阴影移除,无需导航栏颜色更改

问题描述

UINavigationBar我的场景,我试图从使用iOS 13 - Swift 5中删除底线和阴影。在这里,在iOS 13 - Swift 5之前,我使用下面的代码来移除底线和阴影而不改变导航栏颜色。现在,它没有显示NavigationBar颜色(我已经设置了条形颜色和背景颜色)也禁用了 Transulent。

代码:

UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)

如何解决这个问题?需要去除底线阴影并且还想给 NavigationBar 颜色。

标签: iosswift

解决方案


对我来说,它只有在更改以下(> = iOS13)后才有效

let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.shadowColor = .clear
navBarAppearance.shadowImage = UIImage()
navigationController?.navigationBar.standardAppearance = navBarAppearance
navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance

推荐阅读