How to set the title of UIButton as left alignment?

后端 未结 12 2019
感动是毒
感动是毒 2020-11-27 08:34

I need to display the email address from left side of a UIButton, but it is being positioned in the centre.

Is there any way to set the alignment to the

12条回答
  •  抹茶落季
    2020-11-27 09:25

    Set the contentHorizontalAlignment:

    emailBtn.contentHorizontalAlignment = .left;
    

    You might also want to adjust the content left inset otherwise the text will touch the left border:

    emailBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    // Swift 3 and up:
    emailBtn.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0);
    

提交回复
热议问题