Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change default layoutMargins of view

Since ios 8.0 views have additional layoutMargins which by default has an 8 points values for every side.

When I try to change margins in viewDidLoad it seems to have no effect on the child views:

override func viewDidLoad(){
    super.viewDidLoad()
    self.view.layoutMargins = UIEdgeInsets(top:100, left:100, bottom:100, right:100)

}

..itd does not seem to have any effect and

like image 972
aldorain Avatar asked Sep 11 '14 10:09

aldorain


People also ask

What are insets in IOS?

Overview. Edge inset values are applied to a rectangle to shrink or expand the area represented by that rectangle. Typically, edge insets are used during view layout to modify the view's frame. Positive values cause the frame to be inset (or shrunk) by the specified amount.

What is Layoutmarginsguide?

A layout guide representing the view's margins.

What is layout margin IOS?

Layout margins provide a visual buffer between a view's content and any content outside of the view's bounds. The layout margins consist of inset values for each edge (top, bottom, leading, and trailing) of the view.

What is constraint to margin in Xcode?

Feb 25, 2015 at 9:01. It is worth it to point out that when adding new constraints, newer versions of Xcode allow you to uncheck a box for "Constrain to Margins" that sets the same "Relative to Margins" flag. This is useful because it saves a few clicks!


1 Answers

You are trying to set the layout margin of a root view of a view controller. The root view behaves differently than any other view in the hierarchy in regard of the layout margins.

Layout margins of a root view are managed exclusively by the view controller, you can not set them.

From Apple documentation:

If the view is a view controller’s root view, the system sets and manages the margins. The top and bottom margins are set to zero points. The side margins vary depending on the current size class, but can be either 16 or 20 points. You cannot change these margins.

https://developer.apple.com/reference/uikit/uiview/1622566-layoutmargins

like image 116
Denis Krivitski Avatar answered Oct 13 '22 00:10

Denis Krivitski