Make UISearchBar background clear

后端 未结 17 1207
野的像风
野的像风 2021-01-07 17:17

I am not able to clear search bar I have tried to make it clear by setting its background color clear and I have also placed one image under searchbar

I have also ma

17条回答
  •  -上瘾入骨i
    2021-01-07 17:33

    For iOS 13+ we can simply use:

    searchBar.searchTextField.backgroundColor = .clear
    

    but other solutions like:

    searchBar.setSearchFieldBackgroundImage(UIImage(), for: .normal)
    searchBar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
    

    creates a background on the searchBar which hides the placeholder and doesn't allow to interact with the searchBar. The solution for iOS 12 and below is to use an approach similar to @Get Schwifty.

提交回复
热议问题