Use @2x retina images for ipad in universal app? and does apple prefer native apps?

后端 未结 4 817
梦如初夏
梦如初夏 2020-12-23 15:27

I know there were some discussions about this but i could not find good answer?

My questions are -

  1. I know that -

      [UIImage imageNam         
    
    
            
4条回答
  •  春和景丽
    2020-12-23 16:17

    I improved on Bogatyr's answer by checking if the retina image exists. Probably not overly necessary, but I found it useful when testing so I can just create one image file.

    + (UIImage *) imageNamedSmart:(NSString *)name {
        NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
        NSString *retinaFileName = [NSString stringWithFormat:@"%@@2x", name];
    
        NSString *filePath = [[NSBundle mainBundle] pathForResource:retinaFileName ofType:@"png"];
    
        if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && [fileManager fileExistsAtPath:filePath]) {
            return [UIImage imageNamed:[retinaFileName stringByAppendingString:@".png"]];
        }
        return [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", name]];
    }
    

提交回复
热议问题