Is there a way to add some sort of offset to UIButton
's background image?
I've got some custom background images for UIButton
. These images do have a 5 pixel drop shadow area around the effective button area. When I use these images I have to move the title label around, adjust the frame and do some calculations to place the buttons correctly.
Ideally, I would like to set something like an offset (x = -5px, y = -5px) on that image (or the UIButton
) so that when I assign the image as a background to the UIButton it is moved by that offset horizontally and vertically.
In html I would set a fixed size on the button div and then offset the background image by specifying background-position.
Is there something similar for iOS?
Setting setTitleEdgeInsets:
or setImageEdgeInsets:
do not seem to have any effect on the background image of an UIButton
but only on the image (and the title).
I ended up with overriding -(CGRect)backgroundRectForBounds:(CGRect)bounds
where I inflate the bounds rectangle by the amount needed (5 in my case).
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