Disable Safe Area Layout Guides For UIView Programmatically
Asked Answered
E

2

9

Safe area layout guides can be disabled in Interface Builder by unchecking the Use Safe Area Layout Guides. How can this be done in code?

I didn't notice an iOS11-available boolean that directly corresponds with the checkbox.

Elburt answered 10/11, 2017 at 18:25 Comment(3)
Why are you trying to disable safe area layout guides in code? In code you can specify whether you are constraining views to the safe area or not.Statehood
UIView’s safeAreaInsets are not zero and rendering on screen when insetsLayoutMarginsFromSafeArea is false.Elburt
Also safeAreaLayoutGuide is a readonly property on UIView, so this isn't just some that applies to xibs and storyboards in Interface Builder. I just don't know how to disable it.Elburt
S
3

I think the only way to accomplish this programmatically is to override the safeAreaLayoutGuide property.

override var safeAreaLayoutGuide: UILayoutGuide {
    return UILayoutGuide()
}

When you disable it through IB it still returns a UILayoutGuide but with zero layoutFrame, by returning an instance of UILayoutGuide, you are basically doing the same.

Spool answered 19/3, 2018 at 17:54 Comment(0)
L
-1

You can do it in size inspector pane of the view: enter image description here

Limbic answered 3/12, 2022 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.