Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.)

like image 463
maidi Avatar asked Apr 08 '15 10:04

maidi


Video Answer


1 Answers

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!:-)

like image 173
Suran Avatar answered Oct 19 '22 08:10

Suran