【发布时间】:2019-07-13 11:35:52
【问题描述】:
这个页面有tableView和SearchController。我的问题是 searchController 边框。我无法删除边框
我试过了: Remove border between View and Search Bar
Remove navigation bar bottom line when using search controller
Remove 1px line at top of UISearchController in large titles UINavigationBar
How to hide UINavigationBar 1px bottom line
How can I remove border bottom of UINavigationBar?
if #available(iOS 11.0, *) {
let scb = searchController.searchBar
scb.tintColor = UIColor.white
scb.barTintColor = UIColor.white
scb.layer.masksToBounds = true
scb.layer.borderWidth = 10
scb.layer.borderColor = UIColor.clear.cgColor
if let textfield = scb.value(forKey: "searchField") as? UITextField {
textfield.layer.borderWidth = 2
textfield.layer.borderColor = UIColor.clear.cgColor
//textfield.textColor = // Set text color
if let backgroundview = textfield.subviews.first {
// Background color
backgroundview.backgroundColor = UIColor.white
backgroundview.layer.borderWidth = 0
backgroundview.layer.borderColor = UIColor.clear.cgColor
// Rounded corner
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
if let navigationbar = self.navigationController?.navigationBar {
navigationbar.barTintColor = UIColor.clear
}
navigationItem.hidesSearchBarWhenScrolling = false
}
navigationItem.searchController = searchController
navigationItem.largeTitleDisplayMode = .never
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white,NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18, weight: .bold) ]
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Candies"
navigationItem.searchController = searchController
definesPresentationContext = true
如何解决这个问题?有人有想法吗?
【问题讨论】:
-
这是导航栏分隔视图而不是 SearchBar。再次检查
-
试试这个:让 navigationBar = navigationController!.navigationBar navigationBar.setBackgroundImage(#imageLiteral(resourceName: "BarBackground"), for: .default) navigationBar.shadowImage = UIImage()
-
感谢您的回答。当你删除它 SearchController 迷路了。您的代码输出:imgur.com/nQ8ogmx
标签: ios swift border searchbar