Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Safe Area Layout Guides For UIView Programmatically

Tags:

ios

ios11

xcode9

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.

like image 462
kev Avatar asked Nov 10 '17 18:11

kev


People also ask

How do I turn off safe area in Xcode?

You can disable safe area layout guide from storyboard for particular view controller. Select View Controller -> File Inspector (first tab) -> Use safe area layout guides (uncheck the checkbox). You can also change it programmatically in viewDidLoad(). Hope this Helps!

How do I get rid of safe area Xib?

Enabling/Disabling Safe Area Layout Guide If you are creating a new xib or an storyboard in Xcode 9, safe area layout guide option is already enabled. You can disable this option explicitly by going into file inspector menu of Interface Builder and unchecking the option Use Safe Area Layout Guide.

How do I change the safe area in Xcode?

To use the new safe area, select Safe Area Layout Guides in the File inspector for the view controller, and then add constraints between your content and the new safe area anchors. This prevents your content from being obscured by top and bottom bars, and by the overscan region on tvOS.


1 Answers

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.

like image 159
gmogames Avatar answered Sep 20 '22 20:09

gmogames