Make UISearchBar background clear

后端 未结 17 1263
野的像风
野的像风 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条回答
  •  长情又很酷
    2021-01-07 17:40

    For iOS 12, swift 4.x A bit too hacky but Debug view hierarchy shows _UISearchBarSearchFieldBackgroundView is responsible to the background color. To get to it, ...

    for subview in searchBar.subviews.last!.subviews {
       if subview.isKind(of: NSClassFromString("UISearchBarTextField")!) {
           for v in subview.subviews {
              if v.isKind(of: NSClassFromString("_UISearchBarSearchFieldBackgroundView")!) {
                      v.removeFromSuperview()
                    }
                }
            }
        }
    

    This is all too hacky. I prefer asking designer to accept Apple default color.

提交回复
热议问题