title: UISearchBar overlaps status bar in iOS
body: <p>I (just like everyone else here) am running into the same Status Bar overlap issue that everyone else is, with a little twist, and that is why I opening a new question about this. </p>
  
  <p>There seems to be some mechanism that lets the UISearchBar know where to position it self, which is <strong>totally</strong> out of whack.</p>
  
  <p>jaredsinclair answer here (<a href="https://stackoverflow.com/questions/18294872/ios-7-status-bar-back-to-ios-6-style">iOS 7 status bar back to iOS 6 default style in iPhone app?</a>) , explains in great detail how the Apple Engineers allow us to introduce logic to our application in order to blend in as much as possible with the user's environment.</p>
  
  <p>I went through the process of carefully examining each UIViewController in my application and making the slightest modification possible.</p>
  
  <p>In most cases I was able to resolve the problem using the code below which I found accross several SO answers</p>
  
  <pre><code>// Do any additional setup after loading the view.
  if ([self respondsToSelector:@selector(edgesForExtendedLayout)]){
      self.edgesForExtendedLayout = UIRectEdgeNone;
  }
  </code></pre>
  
  <p>This however would not work no matter what I do in a particular view where the UINavigationBar is hidden.</p>
  
  <p><img src="https://i.stack.imgur.com/KVhM8.png" alt="UISearchBar on top of status bar "></p>
  
  <p>Based on the solution found across SO I was able to solve this issue by adding the following piece of logic to this particular UIViewController</p>
  
  <pre><code>if ([[[UIDevice currentDevice] systemVersion] floatValue] &gt;= 7.0) {
      CGRect statusBarFrame =  [[UIApplication sharedApplication] statusBarFrame];
      viewFrame.origin.y = viewFrame.origin.y+statusBarFrame.size.height;
  }
  </code></pre>
  
  <p>This pushes the UIViewController <em>n</em> pixels down "depending" on the height of the status bar.</p>
  
  <p>The effect of this is show here</p>
  
  <p><img src="https://i.stack.imgur.com/TMYmM.png" alt="Hacked position UISearchBar"></p>
  
  <p><strong>The problem</strong> is that when I enter the search field the UISearchBar adds by itself a 20px padding on the top, which offsets the entire UI.</p>
  
  <p><img src="https://i.stack.imgur.com/0RC63.png" alt="enter image description here"></p>
  
  <p>This leads me to the conclusion that the UISearchBar tries to adjust itself, and by coincidence it adjust itself the exact same amount as the status bar's height.</p>
  
  <p>If I don't hack the position, once I enter the search field then this auto adjustment aligns the UISearchBar neatly underneath the status bar.</p>
  
  <p>I hope I have detailed my confusion, I am wondering if anybody has any ideas towards a solution.</p>