Autolayout下UIImageView设置Aspect Fit会在图像的上下留白,如下图1
去除上下留白,子类化UIImageView或者添加一个category,修改intrinsicContentSize方法如下:
#import "AspectFitImageView.h"
@implementation AspectFitImageView
- (CGSize)intrinsicContentSize {
CGSize s =[super intrinsicContentSize];
s.height = self.frame.size.width / self.image.size.width * self.image.size.height;
return s;
}
@end
修改后的效果如下图2: