函数作用: 根据文件名称获取资源文件路径
+(NSString *)getResourcesFile:(NSString *)fileName
{
return [[NSBundle
mainBundle] pathForResource:fileName
ofType:nil];
}
当fileName为空时,上面的函数将返回资源文件夹里按名称字母排序排在最前面的那个资源,所以UIImage *image = [UIImage imageWithContentsOfFile:filePath];中的image会指向意想不到的图片,而不会为空路径,所以上面的函数需要加上对文件名为空情况的处理
+(NSString *)getResourcesFile:(NSString *)fileName
{
if ([fileName isEqualToString:@""] || fileName == nil) {
return nil;
}
return [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
}