支持以前iOS版本和弃用方法function的最佳方式

stretchableImageWithLeftCapWidth:topCapHeight:用于resize图像的方法(iOS低于5.0),但在iOS 5中,该方法已弃用,iOS 5有新的resizableImageWithCapInsets:

支持在低于5且低于5的iOS中resize图像的最佳方法是什么? 我知道的第一件事是使用responseToSelector方法。 但也许有人知道其他例子。

支持版本通常非常简单,唯一要避免的缺陷是使用条件构建来决定支持哪些function,因为这需要您为每个版本使用特定的二进制文件。

我会用这样的东西:

NSString* featureVersion = @"5.0"; NSString* systemVersion = [[UIDevice currentDevice] systemVersion]; if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) { [object someIOS5SpecificMethod]; } else { [object alternateMethod]; } 

要使用特定于版本的类,您可以始终使用类似于:

 Class class = NSClassFromString(@"iOS5OnlyClass"); if (class) { id object = [[class alloc] init]; }