我有一个表,其中包含保存在用户库中的图片的路径。然后,我将此路径传递给仅包含 imageView 的 View 。我想用图片填充这个 ImageView 。就像 WhatsApp(当您点击个人资料的图片时)。但是,我的照片总是被裁剪或扭曲。我尝试了不同的方法来做到这一点,但我没有找到最好的方法:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
UIImage *picture = [UIImage imageWithContentsOfFile: self.picturePath]; //I passed this path from the previous View
UIImageView* imageView = [[UIImageView alloc] initWithImage:picture];
CGRect screenRect = [[UIScreen mainScreen] bounds];
imageView.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
imageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:imageView];
}
原创(我想要类似的东西)
我的应用程序
最佳答案
如果您的图像被剪切,原因是您在较小的容器中使用了更高分辨率的图像,并指示您的 imageview 填充,使用此行 imageView.contentMode = UIViewContentModeScaleAspectFill;
将其更改为imageView.contentMode = UIViewContentModeScaleAspectFit;
关于iOS:ImageView 填充图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22013425/