Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is _UILayoutGuide?

I need to know about _UILayoutGuide, like what it is, what it does and why it present in the hierarchy of UIView as a subview with almost always frame = (0,0,0,0).

like image 915
Suryakant Sharma Avatar asked Oct 23 '13 08:10

Suryakant Sharma


People also ask

What is layout guide iOS?

The safe area layout guide is a property of the UIView class and it inherits from the UILayoutGuide class. It was introduced in iOS 11 and tvOS 11. It helps you correctly position views in a layout. The safe area layout guide replaces the top and bottom layout guides of the UIViewController class.

What is Layoutmarginsguide?

A layout guide representing the view's margins.

What is content layout guides?

The Content Layout guide relates to the size of the scrollable content area inside the scroll view. The challenging part is to define enough constraints to let Auto Layout calculate the scrollable content area (Content Layout) width and height, which we will go into in the next section.

How do I add a top layout guide?

In Figure 1: You can see constraint to Top Layout Guide and it will take statusbar as a base. Show activity on this post. Go to View Controller in interface Builder. And Click Show the attributes inspector and then Select Status Bar as Defaults Both will be same.


1 Answers

This is a private Apple class, which is used for topLayoutGuide and bottomLayoutGuide when auto layout is enabled. If your navigation bar is opaque, one of these "views" will be in [0,0]. If your navigation bars are translucent, same view will usually be in [0,64] in portrait (20pt for the status bar + 44pt for the navigation bar). There is an analogous one for the bottom toolbar, if you have one.

The reason it is done this way is so you could define layout constraints, which work with UIView objects.

One thing to notice, if you have some logic which works on subviews, be careful not to include them in your calculations. You can ignore these by testing:

[subview conformsToProtocol:@protocol(UILayoutSupport)]


On iOS 9, there is a new private class, _UILayoutSpacer, which is not a descendant of UIView, but can be used to set up constraints. The system seems to work in a dual mode, where controllers loaded from xibs and storyboard still use _UILayoutGuide, while controllers created in code are set up using _UILayoutSpacer.

like image 70
Léo Natan Avatar answered Sep 20 '22 11:09

Léo Natan