简体   繁体   English

从url检索到的图像不适合UIImageView

[英]image retrieved from url does not fit properly into UIImageView

I'm trying to download an image from an url and display into a cell (sample below): 我正在尝试从网址下载图像并显示到单元格中(以下示例):

NSURL *url = [NSURL URLWithString:@"http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif"];

NSData *data = [NSData dataWithContentsOfURL:url];

[cell.imageView setImage:[UIImage imageWithData:data]];

Somehow when I display into the cell, it covers the whole cell, bigger than my UIImageView. 当我以某种方式显示到单元格中时,它覆盖了整个单元格,大于UIImageView。

But If I display the image locally like below: 但是,如果我在本地显示图像,如下所示:

[cell.imageView setImage:[UIImage imageNamed:@"defaultProfile.png"]];

It fits perfectly into the UIImageView I set into the cell. 它完全适合我在单元格中设置的UIImageView。

Why is this the case? 为什么会这样呢?

使用imageview的scaleToFit属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM