问题描述
我正在尝试使用Interface Builder中的可拉伸图像设置UIButton背景.按钮配置为自定义",并且我已经为其分配了背景图片.视图模式设置为缩放以填充",但是当我在拉伸"区域中设置任何值时,它似乎无能为力.
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.
我尝试以编程方式执行此操作,并且可以使用UIImage的 stretchableImageWithLeftCapWidth:topCapHeight:
消息来工作,但Apple不建议使用它.
I have tried doing it programmatically and it works using the UIImage's stretchableImageWithLeftCapWidth:topCapHeight:
message, but its use is not recommended by Apple.
有什么方法可以使它在Interface Builder中工作吗?
Is there any way to make it work from Interface Builder?
推荐答案
不幸的是,您不能在当前版本的Xcode 4中使用可拉伸/可调整大小的图像.您必须以编程方式进行操作.
Unfortunately, you can't use stretchable/resizable images in the current version of Xcode 4. You have to do it programmatically.
假设您在谈论iOS 5:SDK仍在NDA下使用了几天,所以我不能更具体了.但只是提示:苹果公司不鼓励使用 stretchableImageWithLeftCapWidth:topCapHeight:
.如果您再次查看此方法的文档(iOS 5版本),则会在此处找到答案.
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.
这篇关于在Interface Builder(XCode 4)中设置UIButton拉伸的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!