我是swift
的新手,我使用搜索功能
加载视图时,searchBar
很好,但是当它开始编辑时,会出现一个阴影,我想将其删除
我在TextDidChange
尝试了此代码,但它没有工作
searchBar.barTintColor = UIColor.clear
searchBar.backgroundColor = UIColor.clear
searchBar.isTranslucent = true
searchBar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
Screenshot Before Editing , Screenshot After Editing
代码:
func addSearchbar(){
if #available(iOS 11.0, *) {
let sc = UISearchController(searchResultsController: nil)
let scb = sc.searchBar
scb.showsCancelButton = false
if let navigationbar = self.navigationController?.navigationBar {
//navigationbar.tintColor = UIColor.green
//navigationbar.backgroundColor = UIColor.yellow
navigationbar.barTintColor = UIColor.white
}
navigationController?.navigationBar.tintColor = UIColor.green
navigationItem.searchController = sc
navigationItem.searchController?.searchBar.delegate = self
navigationItem.searchController?.searchBar.barStyle = .blackTranslucent
navigationItem.hidesSearchBarWhenScrolling = false
}
}