maidi
maidi

Reputation: 3459

Center two-lined Button Title

I want my button title to be centered and simply selected word-wrap in the Attributes Inspector to have two lines.

But the second line is not displayed centered but starts at the same position as the first line (the first line is longer).

How can I center both lines? (I'm using Swift.)

Upvotes: 5

Views: 3182

Answers (1)

Suran
Suran

Reputation: 1227

You cannot set the text alignment of UIButton in interface builder. Create and connect an IBOutlet for the said button in interface builder, and use the following code in viewDidLoad method of the view controller.

ibOutletOfButton.titleLabel.textAlignment = NSTextAlignment.Center;

I hope it helps!:-)

Upvotes: 11

Related Questions