3

I have read multiple previous posts on Autolayout and the status bar behavior in iOS 7 and still do not know how to get my Autolay-ed out objects to be beneath the status bar.

I currently have

self.automaticallyAdjustsScrollViewInsets = YES;
self.edgesForExtendedLayout = UIRectEdgeNone;

and a search bar has a visual format applied like V:|-0-searchBar-|.

The search bar renders under the status bar like enter image description here as expected.

I have been unable to find a solution to get the search bar to start at the bottom edge of the status bar. How can this be done?

EDIT: I have looked at the top layout option, but I have a xib for my Custom View Controller. There is no top layout guide available. How can I support this setup? I would like to avoid checking the system version. ib screenshot

ansonl
  • 786
  • 1
  • 13
  • 34

2 Answers2

1

You need to use the topLayoutGuide.

Apple has a great guide on this issue: https://developer.apple.com/library/ios/qa/qa1797/_index.html

runmad
  • 14,846
  • 9
  • 99
  • 140
  • Thank you for the link, I tried it before, but I have a xib just for my custom view controller class and there is no `topLayoutGuide` for the xib. – ansonl May 25 '15 at 04:29
0

I was able to programmatically access the top guide by following this answer. I was using XIBs for my custom class and thus could not access the topLayoutGuide through the graphical interface builder as seen below.

ib screenshot Instead topLayoutGuide can be accessed through [self topLayoutGuide], where self is the UIViewController. Documentation link

if ([self respondsToSelector:@selector(topLayoutGuide)]) {
    id topGuide = [self topLayoutGuide];
    NSDictionaryOfVariableBindings(topGuide ...
Community
  • 1
  • 1
ansonl
  • 786
  • 1
  • 13
  • 34