【发布时间】:2017-04-15 21:29:45
【问题描述】:
我以编程方式在视图控制器上添加了一个 uiview 作为子视图(称为 contentView)。我还以编程方式在该 uiview 上添加了图像。每次我在 iPad 上运行应用程序时,图像都会被拉伸!如何修复图像以使其适合 iPad 屏幕但不拉伸图像?我知道drawInRect 是在拉伸图像。那么我该如何解决呢?
这是我的代码:
UIGraphicsBeginImageContextWithOptions(self.contentView.bounds.size, self.contentView.opaque, 0.0);
[[UIImage imageNamed:@"menu image 2.JPG"] drawInRect:self.contentView.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.contentView addSubview:imageView];
【问题讨论】:
-
这样复杂的图像分配有什么原因吗?
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menu image 2.JPG"]];- 这应该是所有需要的。为此创建新的图像上下文似乎有点过头了。
标签: ios objective-c uiimageview uiimage