Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alignment the text of button to the left?

Tags:

ios

iphone

Now I want to alignment the text of button to the left with code , how to do ? and I code this :

button.titleLabel.textAlignment = UITextAlignmentLeft; 

but it doesn't work.

like image 877
jin Avatar asked Nov 12 '10 07:11

jin


People also ask

How do I align a text button?

We can align the buttons horizontally as well as vertically. We can center the button by using the following methods: text-align: center - By setting the value of text-align property of parent div tag to the center. margin: auto - By setting the value of margin property to auto.

What is the shortcut for aligning text to the left?

To make text justified, select and highlight the text first, then hold down Ctrl (the control key) on the keyboard and then press J. To make the text left aligned again, press and hold down Ctrl on the keyboard and press L.


2 Answers

You have to use contentVerticalAlignment and contentHorizontalAlignment of the button.

like image 177
AlexVogel Avatar answered Oct 02 '22 13:10

AlexVogel


Use ContentHorizontalAlignment as below

btnObj.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 
like image 30
AP_ Avatar answered Oct 02 '22 14:10

AP_