How to implement scale-9 (9-slice) for custom wallpaper created for UIButton

What do I need to do programmatically in order to use the same background image for a variable-sized UIButton? (commonly called 9-slice scaling or 9-scale)

+6
ios uikit
source share
2 answers

Departure:

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight 

In the UIImage class.

If I understand correctly what you are looking for, this will allow you to use one png to determine what your button looks like and will stretch to any size vertically or horizontally.

+6
source share

I know that this is an old thread, but for everyone who came across this after the release of iOS 5, it should be noted that from the Apple documentation it should be noted that the stretchableImageWithLeftCapWidth: topCapHeight: method is deprecated from iOS 5:

Deprecated UIImage Methods

Deprecated in iOS 5.0. Outdated. Use resizableImageWithCapInsets : instead, specify inserts with a cover so that the inner area is 1x1.

So, now that iOS 6 has been announced and will be available soon, any developer for iOS 5 and above should probably take a look at resizableImageWithCapInsets , which documentation can be found here:

UIImage class reference - resizableImageWithCapInsets

Just thought that I mentioned this to help developers who need an updated answer to this problem.

+15
source share

All Articles