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.
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.
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.
You have to use contentVerticalAlignment
and contentHorizontalAlignment
of the button.
Use ContentHorizontalAlignment
as below
btnObj.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With