iOS:ImageView 填充图片

标签 ios objective-c

我有一个表,其中包含保存在用户库中的图片的路径。然后,我将此路径传递给仅包含 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];
}

Original Image, I want to show this 原创(我想要类似的东西)

My app我的应用程序

最佳答案

如果您的图像被剪切,原因是您在较小的容器中使用了更高分辨率的图像,并指示您的 imageview 填充,使用此行 imageView.contentMode = UIViewContentModeScaleAspectFill;

将其更改为imageView.contentMode = UIViewContentModeScaleAspectFit;

关于iOS:ImageView 填充图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22013425/

相关文章:

ios - NSInternalInconsistencyException : must register a nib or a class for the identifier or connect a prototype cell in a storyboard

ios - 如何将我们在健康应用程序中输入的高度和体重数据读取到我们的自定义应用程序

c# - 单点触控/三20 : Add many items to the first page of TTLauncherView

ios - 如何限制在文本字段中输入的年份的大小

ios - 在 Objective C 中使用 iOS 在 CoreData 中创建与属性的关系

ios - UISearchController UITableView 旋转显示

ios - 从 MSConversation 访问以前的 MSMessage

ios - 使用嵌套 ScrollView 时滚动获取 "stuck"

ios - 蓝牙经典连接感知

ios - 如何在Objective-c的Xcode中使UIImage工作