Make UISearchBar background clear

后端 未结 17 1224
野的像风
野的像风 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条回答
  •  Happy的楠姐
    2021-01-07 17:35

    Here's my solution in Swift 3 (a combo of Scarafone's and Andrew2M's answers):

    for view in searchBar.subviews.last!.subviews {
            if type(of: view) == NSClassFromString("UISearchBarBackground"){
                view.alpha = 0.0
            }
    }
    

    or alternatively:

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

提交回复
热议问题