title: iOS: Programmatically align UIImageView to bottom using anchors
body: <p>I am trying to create an <code>UIImageView</code> programmatically (so no storyboard/UI editor), and align it using anchor constraints.
  The UIImageView should be aligned to the bottom and be scaled to fit the bottom area (like a full-width footer), but maintain aspect ratio, kind of like <strong>what is available in the Storyboard editor?</strong></p>
  
  <p><a href="https://i.stack.imgur.com/Uw9nt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uw9nt.png" alt="enter image description here"></a></p>
  
  <p>My current code in <code>viewDidLoad()</code> looks like this, but no matter what I do, the image is displayed at the top and it seems the ImageView (not the image) fills the entire height of the parent view.</p>
  
  <pre><code>// Create and add image view
  let imgView = UIImageView(image : UIImage(named : "Images/main_bottom.png"))
  imgView.translatesAutoresizingMaskIntoConstraints = false
  imgView.contentMode = .scaleAspectFit
  
  view.addSubview(imgView)
  
  
  // Align image view
  let margins = view.safeAreaLayoutGuide
  
  NSLayoutConstraint.activate([
      imgView.leadingAnchor.constraint(equalTo: margins.leadingAnchor),
      imgView.trailingAnchor.constraint(equalTo: margins.trailingAnchor),
      imgView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  ])
  </code></pre>