title: iOS 11 UISearchBar background color
body: <p>I understand that this question has been asked many, <strong>many</strong> times on SO. However, as Apple does best, with the release of <strong>iOS 11</strong>, they seem to have made a seemingly unnecessary change to the <code>UISearchBar</code>, specifically it's view hierarchy.</p>
  
  <p>In further, the "text field" of a search bar is no longer accessible in the search bar's subviews, causing <strong>all</strong> of the previous solutions to "access" and change the background color of the text field, or any property of the text field for that matter. </p>
  
  <ul>
  <li>Does anyone know how to <strong>actually</strong> adjust the background color of a search bar in <strong>iOS 11</strong>?</li>
  </ul>
  
  <p><strong>FYI:</strong>
  I am specifically talking about the color behind the text... which now as of 11 defaults to white unless you specify the search bar style to be minimal.</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>Since my posting of this question, I still have not found a valid or really <em>any</em> <strong>real solution</strong> to this issue. The closest I have seem to come is to dive deep into the appearance for instance properties</p>
  
  <pre><code>[[UISearchBar class] appearanceWhenContainedInInstancesOfClasses:(nonnull NSArray&lt;Class&lt;UIAppearanceContainer&gt;&gt; *)]
  </code></pre>
  
  <p>of the <code>UISearchBar</code>. Playing around with the found <code>UITextField</code> via methods such as the following:</p>
  
  <pre><code>if ([view isKindOfClass:[UITextField class]]) {
      return (UITextField*)view;
  }
  UITextField *searchTextField;
  for (UIView *subview in view.subviews) {
      searchTextField = [self searchViewForTextFieldBg:subview];
      if (searchTextField) {
          break;
      }
  }
  return searchTextField;
  </code></pre>
  
  <p>you can begin drawing a <strong>new</strong> background view to be placed behind the view. However, the issues I had found too tedious to pursue further were drawing the a view with the correct frame / bounds to mimic exactly the original background. </p>
  
  <p>Hopefully someone can find the <em>actual</em> solution to this problem. Nice miss apple...</p>