获取图片

+(UIImage*)getImageByRetina:(NSString*)imageName

{

 

    float nativeWidth=  MIN([[UIScreen mainScreen] nativeBounds].size.width,[[UIScreen mainScreen] nativeBounds].size.height);

    float screenWidth=   MIN([UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height);

    float currentRatio=nativeWidth/screenWidth;

    if (currentRatio<2) {

      return   [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[imageName stringByAppendingString:@"@2x"]]];

    }else{

     return    [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:imageName]];

    }

    return    [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:imageName]];

}

posted @ 2017-01-23 10:08  Panthera-leo  阅读(112)  评论(0编辑  收藏  举报