Fit image to UIImageVIew in a table view cell

偶尔善良 提交于 2019-12-24 15:37:21

问题


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;

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

Many thanks

Froi


回答1:


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

cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

by:

cell.imageView.contentMode = UIViewContentModeScaleAspectFill;

Hope this Helps ;)



来源:https://stackoverflow.com/questions/9942409/fit-image-to-uiimageview-in-a-table-view-cell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!