开发者

How to check is the @2x Image is exits

there are some images have the @2x version in my project but some image is very small so, I dont need to make the @2x version of them.

My Question is: 开发者_如何学PythonI need to know which version is loaded (regular version or @2x version or ~ipad version), How to check is the @2x version is exist ?

Thanks for reading my question ^^!


You can check it by metod fileExistsAtPath: of NSFileManager


To check if it exists (which is different from loaded), you could do a nil-check:

UIImage *twoXImage = [UIImage imageNamed:@"SomeImageName@2x.png"];
if (!twoXImage)
    // Image does not exist

And if it does exist, you don't have to look through the file system again to grab that—just use the now-existing image. Much more efficient.


NSString *filePath=[[NSBundle mainBundle]pathForResource:@"0"ofType:@"png"];
    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
        NSLog(@"file exixts ");
    } 
    else
    {
        NSLog(@"file not exixits");

    } 

BUT remember it follow the alphabet case of the name provided for file .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜