resizableImageWithCapInsets:resizingMode: 在 iOS 5.1 上崩溃 [英] resizableImageWithCapInsets:resizingMode: crashing on iOS 5.1

查看:34
本文介绍了resizableImageWithCapInsets:resizingMode: 在 iOS 5.1 上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码正确拉伸图像,但是在 iOS 5.1 上它崩溃了.如果我从最后删除 resizingMode,它会工作,但图像会被平铺并且看起来很有趣.知道为什么会崩溃吗?

I'm using this code to stretch an image correctly, however on iOS 5.1 it crashes. If I remove the resizingMode from the end, it works but the image is then tiled and looks funny. Any ideas why it's crashing?

谢谢

self.scrollViewImage.image = [[UIImage imageNamed:@"SysInfoBackBox"] resizableImageWithCapInsets:UIEdgeInsetsMake(40, 40, 40, 40) resizingMode:UIImageResizingModeStretch];

推荐答案

这是 iOS 6.0 中引入的新方法,以前的版本不支持.如果您想让代码在以前的版本上运行,则必须在运行时检查 UIImage 实例是否响应该方法的选择器,如果没有,则实施替代方案.

It's a new method introduced in iOS 6.0 and not supported on previous versions. If you want to make the code run on previous versions, you will have to check at runtime if UIImage instance responds to selector for that method and implement alternative if it doesn't.

if ([UIImage instancesRespondToSelector:@selector(resizableImageWithCapInsets:resizingMode:)]) {
    self.scrollViewImage.image = [[UIImage imageNamed:@"SysInfoBackBox"] resizableImageWithCapInsets:UIEdgeInsetsMake(40, 40, 40, 40) resizingMode:UIImageResizingModeStretch];
} else {
    // alternative
}

这篇关于resizableImageWithCapInsets:resizingMode: 在 iOS 5.1 上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆