Adding padding to an UIView

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! 🙂

Update in Swift 5+, It’s

view.bounds = view.frame.insetBy(dx: 10.0, dy: 10.0);

Leave a Comment