How to achieve UIButton / UILabel 'padding' in iPhone app

前端 未结 10 2066
挽巷
挽巷 2021-01-31 13:40

I\'ve got various views in my iPhone application that require padding e.g a custom UIButton with text aligned left, and a UILabel with a background color.

This may be a

10条回答
  •  迷失自我
    2021-01-31 14:02

    I am using auto layout. Solution that worked for me was setting UIButton's contentEdgeInsets.

    ObjC

    button.contentEdgeInsets = UIEdgeInsetsMake(0.0f, 30.0f, 0.0f, 30.0f);
    

    Swift

    button.contentEdgeInsets = UIEdgeInsets(top: 0.0, left: 30.0, bottom: 0.0, right: 30.0)
    

提交回复
热议问题