UIButton Text Margin / Padding

后端 未结 9 1128
名媛妹妹
名媛妹妹 2021-01-31 13:39

I have the following layout, and I\'m trying to add a padding to the left and right..

The controls are a disabled UIButton.

9条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 13:52

    In Swift 4, note the use of contentEdgeInsets not titleEdgeInsets:

    btn.contentEdgeInsets =  UIEdgeInsetsMake(8, 8, 8, 8)
    btn.titleLabel?.lineBreakMode = .byWordWrapping
    

    That will make the button wrap its text and keep it one line as long as there is a space for it + adding some padding around

提交回复
热议问题