8

I have a UIButton created programmatically but can't find a way to left align the title.

This does nothing:

button.setTitle("DESCRIPTION", for: .normal)
button.titleLabel?.textAlignment = .left
markhorrocks
  • 1,199
  • 19
  • 82
  • 151

2 Answers2

36

Try this one

button.contentHorizontalAlignment = .left
asvetly
  • 1,739
  • 16
  • 17
0

For left side aligment:

buttonItem.contentHorizontalAlignment = .left

For right side aligment:

buttonLogout.contentHorizontalAlignment = .right

and bydefault alignment for button title is center.

Mr.Javed Multani
  • 12,549
  • 4
  • 53
  • 52