title: How to add multiple textfields programatically in swift ios
body: <p>I am trying to show multiple <code>textFields</code> by running a loop, that whether the number of textfields <code>noTextField</code> is greater than zero (which is an input value), it should display the multiple textFields on <code>ViewController</code>.</p>
  
  <p>Here is what I have one textfield and prints multiple <code>hello</code> but could not display multiple textfields.</p>
  
  <p>What I have </p>
  
  <p><a href="https://i.stack.imgur.com/V9Drh.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>What I want </p>
  
  <p><a href="https://i.stack.imgur.com/8ip4q.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <pre><code>            if self.noTextFields! &gt; 0 {
              for _ in 0..&lt;self.noTextFields! {
                 // self.createForm()
                  print ("hello")
  
  
                  let sampleTextField =  UITextField(frame: CGRect(x: 20, y: 100, width: 300, height: 40))
                  sampleTextField.placeholder = "Enter text here"
                  sampleTextField.font = UIFont.systemFont(ofSize: 15)
                  sampleTextField.borderStyle = UITextBorderStyle.roundedRect
                  sampleTextField.autocorrectionType = UITextAutocorrectionType.no
                  sampleTextField.keyboardType = UIKeyboardType.default
                  sampleTextField.returnKeyType = UIReturnKeyType.done
                  sampleTextField.clearButtonMode = UITextFieldViewMode.whileEditing;
                  sampleTextField.contentVerticalAlignment = UIControlContentVerticalAlignment.center
                  sampleTextField.delegate = self as? UITextFieldDelegate
                  self.view.addSubview(sampleTextField)
  
              }
          }
  </code></pre>