swift - 滚动时或直到按下搜索栏时导航栏下方的白线

标签 swift uitableview uinavigationcontroller uinavigationbar uisearchbar

正如您在视频中看到的,当我开始滚动时,导航栏下方有一条白色细线。

它只会在我按下 searchBar 时消失(包含在我的 searchController 中,因此搜索栏不会从 Storyboard 中添加)。我尝试了很多不同的组合,试图让它消失,但没有任何效果。

感谢任何帮助!谢谢!

视频: https://www.youtube.com/watch?v=KcgZmBg1VS0

这是我的 viewDidLoad 中的代码:

searchController.searchBar.delegate = self

searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.placeholder = "Search for a recipe"

searchController.searchBar.barTintColor = navigationController?.navigationBar.barTintColor
searchController.searchBar.tintColor = UIColor.white

最佳答案

尝试设置背景颜色并更改 navigationBar 的阴影。它可能与 navigationBar 相关联。

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()

尝试添加这一行:

searchController.searchBar.backgroundColor = navigationController?.navigationBar.barTintColor

在文件setupSearchBar()

代码修复后:

enter image description here

关于swift - 滚动时或直到按下搜索栏时导航栏下方的白线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497184/

相关文章:

swift - 快速从请求响应中获取 header 数据

快速通用字典功能

swift - 为什么我的父类(super class)在 Swift 中调用子类的方法而不是它自己的方法?

iOS/Xcode/ Storyboard : How to adjust size of UITableView in UIViewController

ios - 隐藏导航栏不起作用

iOS:无法将 UISplitViewController 推送到 UINavigationController

swift - 为什么日期格式化程序正确返回日期但时间显示为 00 :00:00 when converting string to NSDate

ios - 启用为假时不显示按钮文本

iphone - EKEventEditViewController 不支持推送到 NavController 吗?请参阅附加的代码和错误

ios - performSegue - 它会停止进一步的代码执行吗?