I’m trying to center the text of UIButton programmatically.
This is what I want the UIButton to look like (I used the interface builder):
This is what the UIButton looks like after I set it programmatically:
And this is what the UIButton looks like after I set it programmatically and tried to center the text like in the first picture:
This is the code that I used to try to center it:
previousPageButton.titleLabel?.numberOfLines = 0
previousPageButton.titleLabel?.textAlignment = .center
CodePudding user response:
Try adding:
previousPageButton.titleLabel?.lineBreakMode = .byWordWrapping
CodePudding user response:
The problem was I had set up "attributed" to the title in interface builder. I just had to set it to "plain" and it's working now.