title: How to embed a UILabel inside a UIView in swift
body: <p>I need to create a UIView programmaticaly in swift, that view should contain an image and a label. Also I need to embed that label and the imageview inside that created view so that as I animate the constraints of the view, the label and the image shold also reposition itseld relative to the view. This is my code co far -</p>
  
  <pre><code>func banner(viewController:UIViewController){
     let width = UIScreen.main.bounds.width
     let dynamicView=UIView(frame: CGRect(x:0,y: -70, width:width, height:70))
     let label = UILabel(frame: CGRect(x:0,y: 35, width:width, height:20))
     dynamicView.backgroundColor=UIColor.green
     label.center = CGPoint(x: width/2, y: 35)
     label.textAlignment = .center
     label.text = "I'am a test label"
     UIView.animate(withDuration: 1) {
       dynamicView.frame = dynamicView.frame.offsetBy( dx: 0, dy: 70 )
       viewController.view.addSubview(DynamicView)
       viewController.view.addSubview(label)
     }
  
    UIView.animate(withDuration: 1, delay: 3, usingSpringWithDamping: 1, initialSpringVelocity: 4, options: .curveEaseIn, animations: { 
       dynamicView.frame = DynamicView.frame.offsetBy( dx: 0, dy: -70 )
       }, completion: nil)
   }
  }
  </code></pre>
  
  <p>I could achieve that by changing x and y position of each views,labels etc separately. But that code would not be clean and consise. </p>