title: How do I duplicate UIView added to ViewController in StoryBoard and keep constraints?
body: <p>I have created a view, CustomView.xib, and a dedicated class, CustomView.swift.  I have added it to my ViewController in Storyboard by adding a view and setting the custom class to CustomView.swift and it works perfectly. The constraints I added in StoryBoard resize the nib like I want.  Now I want to create copies of it, like cells/rows in a tableView (like a twitterfeed).  How can I do that, while maintaining the constraints so that it resize correctly?  I guess my question boils down to: How do you duplicate UIViews created in StoryBoard? I realise that the top constraint might have to be altered as row's are added. And second, since this is a nib, how can I change the label within it?  The project is on <a href="https://github.com/karlml/CustomViewNib.git" rel="nofollow">GitHub</a></p>
  
  <p>Any help would be very much appreciated! Thank you.</p>
  
  <pre><code>import UIKit
  
  class ScrollViewController: UIViewController {
  
      let scrollView = UIScrollView()
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let height = CGFloat(200.0)
  
          self.scrollView.frame = self.view.bounds
          self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, height*3)
          self.view.addSubview(self.scrollView)
  
  
          var y = CGFloat(0.0)
  
          for i in 0..&lt;2 {
  
              //DO I ADD IBOUTLET(s)?
              // How do I set width of frame to the View in StoryBoard (that has constraints?
              //Do I tag it, give it an ID - How can I create copies of the customView from StoryBoard
  
              let customView = CustomView(frame: CGRectMake(0, y, 320, 200))
              self.scrollView.addSubview(customView)
  
              y += height
          }
  
      }
  
  
  
      func createCustomView(index: Int) -&gt; UIView {
          //How do I instantiate the view here without setting the frame size?
          let customView = CustomView(frame: CGRectMake(0, 0, 320, 200))
  
          if index == 0{
              customView.backgroundColor = UIColor.greenColor()
              //How do I change the label text, like below?
              //customView.label.text = "New York"
          }
  
          if index == 1{
              customView.backgroundColor = UIColor.redColor()
              //How do I change the label text, like below?
              //customView.label.text = "Tokyo"
  
          }
  
          return customView
      }
  
  
  }
  </code></pre>