title: Use background image on UISearchController iOS 11
body: <p>I'm implementing an <code>UISearchController</code> to my <code>UITableView</code> but I'm struggling with the customization for iOS 11. My navigation bar is using a gradient image background that I want the search controller to match, but I haven't found a way to set the background image for <code>UISearchController</code>. It works perfectly on UISearchController as a TableHeaderView, but in iOS 11 barely any customization is passed on.</p>
  
  <p><strong>Current outcome:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/H3NwL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H3NwL.png" alt="Current outcome"></a></p>
  
  <p><strong>Desired outcome:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/B41pP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B41pP.png" alt="Desired outcome"></a></p>
  
  <p><strong>This is the code I'm using:</strong> <em>(called on viewDidLoad)</em></p>
  
  <pre><code>private func setupSearchController() {
  
      let searchController = UISearchController(searchResultsController: nil)
  
      // Convert CAGradientLayer to UIImage
      let gradient = Color.blue.gradient
      gradient.frame = searchController.searchBar.bounds
      UIGraphicsBeginImageContext(gradient.bounds.size)
      gradient.render(in: UIGraphicsGetCurrentContext()!)
      let gradientImage = UIGraphicsGetImageFromCurrentImageContext()
      UIGraphicsEndImageContext()
  
      // Setup the Search Controller
      searchController.searchBar.backgroundImage = gradientImage
      searchController.searchBar.isTranslucent = false
      searchController.searchResultsUpdater = self
      searchController.hidesNavigationBarDuringPresentation = false
      searchController.dimsBackgroundDuringPresentation = false
      searchController.obscuresBackgroundDuringPresentation = false
      searchController.searchBar.placeholder = "Search by transaction name"
      searchController.searchBar.tintColor = Color.custom(hexString: "FAFAFA", alpha: 1).value
      definesPresentationContext = true
      searchController.searchBar.delegate = self
  
      // Implement Search Controller
      if #available(iOS 11.0, *) {
          navigationItem.searchController = searchController
          navigationItem.hidesSearchBarWhenScrolling = false
          navigationController?.navigationBar.setBackgroundImage(gradientImage, for: .default)
      } else {
          tableView.tableHeaderView = searchController.searchBar
      }
  
  }
  </code></pre>