How to alignment the text of button to the left?

后端 未结 5 1957
轻奢々
轻奢々 2021-02-03 18:46

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;
         


        
相关标签:
5条回答
  • 2021-02-03 19:25

    Setting to button titleLable alignment also works perfectly.

    btn.titleLabel.textAlignment=NSTextAlignmentCenter;
    
    0 讨论(0)
  • 2021-02-03 19:26

    For those who are using Swift 3

    button.contentHorizontalAlignment = .left
    

    Above code align text to left border, so you might want little padding.

    button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0)
    
    0 讨论(0)
  • 2021-02-03 19:30

    You have to use contentVerticalAlignment and contentHorizontalAlignment of the button.

    0 讨论(0)
  • 2021-02-03 19:34

    Use ContentHorizontalAlignment as below

    btnObj.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    
    0 讨论(0)
  • 2021-02-03 19:38

    Swift Code

    button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
    
    0 讨论(0)
提交回复
热议问题