title: Creating UILabel programmatically with constraints?
body: <p>What I want to do is create a new UILabel programmatically every time a certain action occurs in my code. I know the x, y, and height that I want to give the label, but I don't want to give it a set width. I want to constrain the sides so that the UILabel width is equal to the width of the screen, and so that the label width will change if the orientation is flipped.</p>
  
  <p>I have considered using:</p>
  
  <pre><code>CGRect(x:, y:, width:, height:)
  </code></pre>
  
  <p>However, I would have to give it a set width if I use this, so I don't think it will work. </p>
  
  <p>I also tried using:</p>
  
  <pre><code>CGPoint(x:, y:)
  </code></pre>
  
  <p>Then setting leading, trailing and height anchors, however, this doesn't seem to work either as even though it does compile, I get an error when I try creating a new UILabel.</p>
  
  <p>I'm kind of new to programming in Swift so I'm not sure if there is an obvious fix to this.</p>