Search code examples
iosswiftsearchios9

IOS UISearchBar Background Color In iOS 9


I have been search a while for this issue , I want my search bar display like BBC News AppSearchBar In BBC News APP

I try all related method

  for view in searchBar.subviews {
        if view.isKindOfClass(NSClassFromString("UISearchBarBackground")!) {
            view.removeFromSuperview()
            break;
        }
  }

    self.searchBar.tintColor = UIColor.clearColor()
    self.searchBar.backgroundColor = UIColor.clearColor()
    self.searchBar.translucent = true

here is my output enter image description here

Am I miss something ??? Please Help me , thx !


Solution

  • Swift 3

    To remove the background altogether, set backgroundImage to an empty image:

    searchBar.backgroundImage = UIImage()
    

    To set a custom background color, use barTintcolor property:

    searchBar.barTintColor = .green