title: Wordwrap label in Swift
body: <p>I searched for this problem but the solutions i found didn't work for me. I have a textfield. When user writes something to textfield, it writes it to the label. This label is on an imageview, when label reaches the imageview limits. I want that label wordwrap and go to second line. Now it is like this but doesn't work.</p>
  
  <pre><code>    @IBAction func textchanged(_ sender: UITextField) { 
      if(mylabel.frame.minX &lt; imageview.frame.minX &amp;&amp; mylabel.frame.maxX &gt; imageview.frame.maxX)
      {
      mylabel.frame = CGRect(x: mylabel.frame.origin.x, y: mylabel.frame.origin.y, width: mylabel.frame.width, height: mylabel.frame.height * 2 )
      mylabel.numberOfLines = 2
      mylabel.lineBreakMode = NSLineBreakMode.byWordWrapping
      mylabel.sizeToFit()
      }
      mylabel.numberOfLines = lines
      mylabel.text = textfield.text
      mylabel.sizeToFit()
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/sGXj3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sGXj3.png" alt="screenshot"></a></p>