title: How to change the layout margins programmatically
body: <p>I have very easy setup in <code>viewDidLoad</code>, just add a view and pin it to superview's margins by 'anchors' style:</p>
  
  <pre><code>let myView = UIView(frame: .zero)
  myView.translatesAutoresizingMaskIntoConstraints = false
  view.addSubview(myView)
  myView.backgroundColor = UIColor.red
  myView.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor).isActive = true
  myView.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor).isActive = true
  myView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor).isActive = true
  myView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor).isActive = true
  view.layoutMargins = .zero
  </code></pre>
  
  <p>The problem is that there is still a margin when running this in simulator. Why layoutMargins zeroing is ignored?</p>
  
  <p><a href="https://i.stack.imgur.com/Doijd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Doijd.png" alt="enter image description here"></a></p>