在表格视图单元格中将图像调整为UIImageVIew [英] Fit image to UIImageVIew in a table view cell

查看:75
本文介绍了在表格视图单元格中将图像调整为UIImageVIew的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码在表格视图单元格中的UIImageVI中调整URL中心的图像:

I'm trying to get centered and fit and centered an image called from URL in a UIImageVI in a table view cell with this code:

NSData *imageData= [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:news.image_small]];

    cell.imageView.image=[UIImage imageWithData:imageData];

    cell.imageView.layer.cornerRadius = 5.0;

    cell.imageView.layer.masksToBounds = YES;

    cell.imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    cell.imageView.layer.borderWidth = 1.0;

    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

但是图像总是大于UIImageVI大小。我该如何解决?

But image is always greater than UIImageVI size. How can I solve it?

非常感谢

Froi

推荐答案

要使图像等于UIImageView大小,最好更换:

To make the image equal to the UIImageView size, you should better replace:

cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

by:

cell.imageView.contentMode = UIViewContentModeScaleAspectFill;

希望这有助于;)

这篇关于在表格视图单元格中将图像调整为UIImageVIew的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆