Adding padding to an UIView

后端 未结 7 1308
长情又很酷
长情又很酷 2020-12-23 12:55

I\'m looking for a way to add a padding property to an UIView. Ideally, I would like to avoid subclassing and putting it in a category. The usage would be somet

相关标签:
7条回答
  • 2020-12-23 14:00

    This is generally done by setting the bounds within the view. So if you wanted an inset of 10 all round you could do:

    view.bounds = CGRectInset(view.frame, 10.0f, 10.0f);
    

    The bounds defines the drawable area of the view, relative to the frame. So this should give in effect a padding. You can then get the 'paddingBox' just from the bounds.

    Hope this helps! :)

    0 讨论(0)
提交回复
热议问题