Vlad
Vlad

Reputation: 5928

iOS 11 how to pin view to safe area bottom anchor

How do I pin a view's bottom anchor to it's superview's bottom safe area anchor in iOS 11 using interface builder?

I have been able to do it programmatically like so:

if (@available(iOS 11.0, *)) {
    [self.myBottomView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor].active = true;
} else {
    [self.myBottomView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = true;
}

When I go to interface builder I cannot see the bottom safe area anchor:

enter image description here

Upvotes: 1

Views: 2684

Answers (1)

Sparga
Sparga

Reputation: 1625

On a project created before Xcode 9, storyboards and xibs are not updated automatically to use the safe areas because the existing constraints needs to be changed manually.

You can enable this with an option in the file inspector (in the right panel): How to enable safe area

Then, the safe area appears like a specific kind a view and you can use it to add your constraints: Adding constraints related to the safe area

Note that it is possible to use the safe area in a storyboard and have a deployment target lower than iOS 11. I tested in the simulator with iOS 10 and it works as expected.

Upvotes: 4

Related Questions