Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Button Title Alignment in Swift?

I am trying to set the title on a Button to left. But everything i tried is not working.

With:

UILabelButton.titleLabel.textAlignment = .Left 

Or:

UILabelButton.contentVerticalAlignment = UIControlContentVerticalAlignment // There is no left 

The button title is still centered.

Is there another Property?

like image 363
derdida Avatar asked Jul 28 '14 22:07

derdida


People also ask

How do I change the button title alignment in Swift?

You have to use UIControlContentHorizontalAlignment. Left . You need to use horizontal not vertical . Save this answer.

How do I change text alignment in Swiftui?

To align a text view along the horizontal axis, you need to use . frame() modifier with maxWidth set to . infinity and alignment to the alignment you want.


1 Answers

Use contentHorizontalAlignment.You have to use UIControlContentHorizontalAlignment.Left.You need to usehorizontal not vertical.

btn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left 

Swift 3.x

btn.contentHorizontalAlignment = .left 
like image 98
codester Avatar answered Sep 23 '22 21:09

codester