我一直通过绕过它来解决这个问题已经有一段时间了,但我真的很想知道正确处理这种情况的方法:
如果我从CoreData中获取NSData格式的图像,例如:
NSData *myImageData = myEntity.Image;
cell.imageView.image = [UIImage imageWithData:myImageData];
[cell.imageView setContentMode:UIViewContentModeScaleAspectFit];
如果图像大于UIImageView的CGRect,则图像不会限制在UIImageView的CGRect中。
我目前使用以下代码来解决此问题:
CGSize size = CGSizeMake(98, 98);
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = scaledImage;
这个方法是有效的,但我希望有人能告诉我使用ContentMode方法时我做错了什么,因为它应该可以工作。
感谢您抽出时间阅读我的问题。