I could not find a way to do this with UIView
, as I depict in the following picture:
It portrays having a image background with a shadow.
Is there anything of the shelf for padding, or do I need to add more child objects to achieve this effect?
I think this would be pretty straightforward to do, but you'll have to implement it yourself.
If I understand your question correctly you'd like to have a padding value added automatically to your subviews - for example, pass an X/Y value of 0, 0
for a button's frame, but have its actual position be 10, 10
.
I haven't fully fleshed this out, but you'd probably need to create a UIView
subclass that had two extra bits - firstly, a 'padding' property (probably a UIEdgeInset
), and then override the setFrame
setter to automatically add the correct amount of padding to a frame. You could, say, have an initWithFrame:padding:
method to create objects. You could even have your UIView subclass automatically query the superview to obtain the padding.
There's a lot of scope here - so I guess to answer your question, no - there isn't anything off the shelf - but implementing it yourself is pretty achievable and probably quite fun as well!
(assuming you find doing this sort of thing fun, of course...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With