简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM