Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting UIButton stretched background images in Interface Builder (XCode 4)

Tags:

ios

iphone

I'm trying to set up an UIButton background using a stretchable image in Interface Builder. Button is configured as "custom" and I have assigned a background image to it. The view mode is set to "Scale to Fill", but when I set any value in "Stretching" area it doesn't seems to do anything.

I have tried doing it programmatically and it works using the UIImage's stretchableImageWithLeftCapWidth:topCapHeight: message, but its use is not recommended by Apple.

Is there any way to make it work from Interface Builder?

like image 249
Antonio Fernández Vega Avatar asked Oct 09 '22 19:10

Antonio Fernández Vega


1 Answers

Unfortunately, you can't use stretchable/resizable images in the current version of Xcode 4. You have to do it programmatically.

Assuming that you are talking about iOS 5: the SDK is still under NDA for a few days, so I can't be more specific. But just as a hint: Apple doesn't discourage the use of stretchableImageWithLeftCapWidth:topCapHeight:. If you look at the documentation (iOS 5 version) of this method again, you will find an answer there.

like image 95
klaussner Avatar answered Oct 13 '22 12:10

klaussner