title: Center alignment UIButton xCODE programmatically
body: <p>I’m trying to center the text of UIButton programmatically.</p>
  <p>This is what I want the UIButton to look like (I used the interface builder):</p>
  <p><a href="https://i.stack.imgur.com/GXWIL.png" rel="nofollow noreferrer">UIbutton</a></p>
  <p>This is what the UIButton looks like after I set it programmatically:</p>
  <p><a href="https://i.stack.imgur.com/2A6LV.png" rel="nofollow noreferrer">UIbutton</a></p>
  <p>And this is what the UIButton looks like after I set it programmatically and tried to center the text like in the first picture:</p>
  <p><a href="https://i.stack.imgur.com/zWsLU.png" rel="nofollow noreferrer">UIButton</a></p>
  <p>This is the code that I used to try to center it:</p>
  <pre><code>previousPageButton.titleLabel?.numberOfLines = 0
  
  previousPageButton.titleLabel?.textAlignment = .center
  </code></pre>