UIImageView contentMode在视网膜和非视网膜显示方面不同

时间:2012-10-25 13:23:43

标签: iphone objective-c ios uiimageview

所以我有这个UIImageView,上面有一个图像。当我使用普通的iPhone显示器时,它会在UIImageView内完全按照预期显示在UIImageView范围内,问题是当我使用视网膜显示设备时,图像变大,不适合UIImageView边界,它遍布整个屏幕。

如何解决此问题?我希望Retina显示屏中的图像适合UIImageView尺寸。

这是我的代码:

- (UIImage *)loadScreenShotImageFromDocumentsDirectory
{
    UIImage * tempimage;
    NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
    NSString *docDirectory = [sysPaths objectAtIndex:0];
    NSString *filePath = [NSString stringWithFormat:@"%@/MeasureScreenShot.png", docDirectory];
    tempimage = [[UIImage alloc] initWithContentsOfFile:filePath];

    return tempimage;
}

- (void)viewDidLoad
{
    // Setting the image
    UIImage * Image = [self loadScreenShotImageFromDocumentsDirectory];
    theImageView.frame = CGRectMake(0, 166, 290, 334);
    theImageView.contentMode = UIViewContentModeCenter;        
    theImageView.image = Image;
}

提前感谢!

2 个答案:

答案 0 :(得分:1)

尝试将内容模式设置为UIViewContentModeScaleAspectFit

答案 1 :(得分:0)

当我使用带有核心图的图像时,我不得不缩放视网膜显示的图像。

 CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage scale:bubble.scale];

图像文件的名称是bubble,我有一个气泡文件和一个bubble @ 2x文件。这使图像适合任一显示的图像视图。希望这会有所帮助。

相关问题