问题
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