简体   繁体   English

在Interface Builder(XCode 4)中设置UIButton拉伸背景图像

[英]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. 我正在尝试使用Interface Builder中的可伸缩图像设置UIButton背景。 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. 我已尝试以编程方式执行此操作并使用UIImage的stretchableImageWithLeftCapWidth:topCapHeight:消息,但Apple不建议使用它。

Is there any way to make it work from Interface Builder? 有没有办法让它从Interface Builder工作?

Unfortunately, you can't use stretchable/resizable images in the current version of Xcode 4. You have to do it programmatically. 不幸的是,您无法在当前版本的Xcode 4中使用可伸缩/可调整大小的图像。您必须以编程方式执行此操作。

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. 假设你在谈论iOS 5:SDK仍然在NDA下几天,所以我不能更具体。 But just as a hint: Apple doesn't discourage the use of stretchableImageWithLeftCapWidth:topCapHeight: . 但只是提示:Apple不会阻止使用stretchableImageWithLeftCapWidth:topCapHeight: . If you look at the documentation (iOS 5 version) of this method again, you will find an answer there. 如果再次查看此方法的文档(iOS 5版本),您会在那里找到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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