我以编程方式在视图控制器上添加了uiview作为子视图(称为contentView)。我还以编程方式在该uiview上添加了一个图像。每次我在iPad上运行应用程序时,图像都被拉长了!如何修复图像,使其适合iPad屏幕,但不会拉伸图像?我知道drawInRect
是拉伸形象。那么我该如何解决这个问题?如何以编程方式使用uiview上的图像
这是我的代码:
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];
没有任何理由对这种复杂的图像assignement? '[[UIImageView alloc] initWithImage:[UIImage imageNamed:@“menu image 2.JPG”]];' - 这应该是所有需要的。为此创建新的图像上下文似乎是一种矫枉过正。 – Losiowaty