Swift 4:删除UISearchbar的编辑阴影

时间:2017-12-13 12:26:56

标签: ios swift

我是swift的新手,我使用搜索功能

构建了一个应用程序

加载视图时,searchBar很好,但是当它开始编辑时,会出现一个阴影,我想将其删除

我在TextDidChange尝试了此代码,但它没有工作

searchBar.barTintColor = UIColor.clear
searchBar.backgroundColor = UIColor.clear
searchBar.isTranslucent = true
searchBar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)

Screenshot Before EditingScreenshot 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
    }
}

0 个答案:

没有答案