"Safe Area" layout guide

I use AutoLayout, but I prefer not to use storyboards. Instead, I generally create independent view controllers with their own XIB files.


Also, I don't like using UITableViewController and UICollectionViewController. Instead, I prefer to add table views and collection views manually to my XIB files.


Will the new "Safe Area" layout guide be available to me using these techniques? Or will I need to write my own code to adjust things for the iPhone X?


Thanks,
Frank

If you pin your tableview and collectionview to the main view controller view's safe area layout guide you should be good.

Hi,


I upgraded to Xcode 9, but I'm not finding this "safe area layout guide" that you mentioned.


When I go to create a constraint between a subview and the main view, I only see top, bottom, leading, trailing, as before.


This is important for me to figure out because some of my views are getting clipped by the navigation bar when I run them in the iPhone X simulator.


Please elaborate on how this is done. Thanks.

I am assuming you are trying to do this in your xib file. You should click on the "File Inspector" and there should be an option to turn on "Use safe area layout guides".


https://www.icloud.com/sharedalbum/#B0PJr1PPdJt0QxL


In code you should be able to something like this:

    [self.tableView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor].active = YES;


Or you could try using the new contentLayoutGuide in scrollViews

    [self.tableView.contentLayoutGuide.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor].active = YES;
"Safe Area" layout guide
 
 
Q