Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resizableImageWithCapInsets:resizingMode: crashing on iOS 5.1

Tags:

xcode

ios

uiimage

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?

Thanks

self.scrollViewImage.image = [[UIImage imageNamed:@"SysInfoBackBox"] resizableImageWithCapInsets:UIEdgeInsetsMake(40, 40, 40, 40) resizingMode:UIImageResizingModeStretch];
like image 596
Darren Avatar asked Dec 11 '22 22:12

Darren


2 Answers

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
}
like image 64
Filip Radelic Avatar answered Dec 14 '22 12:12

Filip Radelic


This function resizableImageWithCapInsets:resizingMode: don't work on ios 5.0 (only >=6.0), but resizableImageWithCapInsets: does, try to use it. Maybe a simple replacement can help you.

like image 22
surfrider Avatar answered Dec 14 '22 12:12

surfrider