title: how to add image view with some constraints programmatically using swift?
body: <p>I am new in iOS Development. If using storyboard, I can place an Image view in view controller like this</p>
  
  <p><a href="https://i.stack.imgur.com/znMKb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/znMKb.png" alt="enter image description here"></a></p>
  
  <p>I need to make something like that programmatically.</p>
  
  <p>so I have custom view from a library called <code>RevealingSplashView</code> , but I need to add an image view to that custom UI View. I just know to add the image view, maybe something like this</p>
  
  <pre><code>let imageName = "yourImage.png"
  let image = UIImage(named: imageName)
  let imageView = UIImageView(image: image!)
  imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 200)
  revealingSplashView.addSubview(imageView)
  </code></pre>
  
  <p>but I don't know how to set that constraint to image view to</p>
  
  <p>a. align to center x to superview</p>
  
  <p>b. proportional width to superview 0.8</p>
  
  <p>c. height constraint = 25</p>
  
  <p>d. align bottom to safe area = 32</p>
  
  <p>how to do that ?</p>
  
  <p>here is the code I use before want to add image view</p>
  
  <pre><code>let screenSize = UIScreen.main.bounds
              let iconWidth = (screenSize.width) * 0.8
              let iconHeight = iconWidth * 1 // ratio 1:1
              revealingSplashView = RevealingSplashView(iconImage: UIImage(named: "Loading Page Asset")!,iconInitialSize: CGSize(width: iconWidth, height: iconHeight), backgroundColor: AppColor.mainYellow.getUIColor())
              revealingSplashView.animationType = SplashAnimationType.twitter
              revealingSplashView.imageView?.contentMode = .scaleAspectFill
  
  
              // add loading indicator to RevealingSplashView Programatically
              revealingSplashViewIndicator.color = UIColor.white
              revealingSplashViewIndicator.frame = CGRect(x: 0.0, y: 0.0, width: 30.0, height: 30.0)
              revealingSplashViewIndicator.center =  CGPoint(x: self.view.center.x, y: self.view.center.y + (iconHeight/2) + 64 )
              revealingSplashView.addSubview(revealingSplashViewIndicator)
              revealingSplashViewIndicator.bringSubviewToFront(self.revealingSplashView)
              revealingSplashViewIndicator.startAnimating()
  
              let window = UIApplication.shared.keyWindow
              window?.addSubview(revealingSplashView)
  </code></pre>