What do I need to do programatically in order to use the same background image for UIButton of variable size? (commonly known as 9-slice scaling or scale-9)
I know this is an old thread, but to anyone who stumbles upon this after iOS 5 is released, it should be noted from Apple's documentation that the stretchableImageWithLeftCapWidth:topCapHeight: method is deprecated as of iOS 5:
Deprecated UIImage Methods
Deprecated in iOS 5.0. Deprecated. Use the resizableImageWithCapInsets: instead, specifying cap insets such that the interior is a 1x1 area.
So now that iOS 6 has been announced and will be here soon, anyone developing for iOS 5 and higher should probably take a look at resizableImageWithCapInsets instead, which documentation can be found here:
UIImage Class Reference - resizableImageWithCapInsets
Just thought I'd mention it to help any developers who needed an updated answer to this problem.
Check out:
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
In the UIImage class.
If I understand what you're looking for correctly, this while allow you to use one png to define how your button looks, and it will stretch to any size vertically or horizontally.
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