我无法弄清楚为什么UIImages
我UIImageViews
的文件没有正确调整到UIImageView
. 任何人都可以阐明我的代码中的问题吗?以下是来自 my 的相关代码SidewalkPlusSuperCell
,它是一个子类UICollectionViewCell
。我正在尝试构建一个UICollectionViewCell
显示UIImage
(传单)的代码,但无法让传单UIImage
适合/调整大小以适应UIImageView
. 我知道我必须设置contentMode
,但无论我在哪里设置contentMode
,图像都保持未调整大小。
//
// SidewalkPlusSuperCell.m
//
#import "SidewalkPlusSuperCell.h"
#import "Masonry.h"
@interface SidewalkPlusSuperCell()
@property (nonatomic) BOOL showInformation;
@property (strong, nonatomic) UIImageView *flyerImageView;
@end
@implementation SidewalkPlusSuperCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_showInformation = NO;
}
return self;
}
- (void)updateConstraints
{
if (_showInformation) {
UIEdgeInsets imagePlusTextPadding = UIEdgeInsetsMake(5, 5, 5, 5);
[_flyerImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.superview.mas_top).with.offset(imagePlusTextPadding.top);
make.leading.equalTo(self.superview.mas_leading).with.offset(imagePlusTextPadding.left);
make.bottom.equalTo(self.superview.mas_bottom).with.offset(imagePlusTextPadding.bottom);
}];
} else {
UIEdgeInsets onlyImagePadding = UIEdgeInsetsMake(0, 0, 0, 0);
[_flyerImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.superview).with.insets(onlyImagePadding);
}];
}
[super updateConstraints];
}
- (void)drawRect:(CGRect)rect
{
if (_showInformation) {
} else {
_flyerImageView = [[UIImageView alloc] init];
[_flyerImageView setFrame:rect];
[_flyerImageView setContentMode:UIViewContentModeScaleAspectFit];
[_flyerImageView setImage:self.flyerImage]; //self.flyerImage is a public property that is set by the UICollectionViewController
[self addSubview:_flyerImageView];
UIEdgeInsets onlyImagePadding = UIEdgeInsetsMake(0, 0, 0, 0);
[_flyerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.superview).with.insets(onlyImagePadding);
}];
[self updateConstraints];
}
}
@end
当我运行代码时,我得到以下信息:
单元格应该是不同的大小(大小基于原始照片的方面),但照片应该调整大小以适合单元格。任何关于为什么UIImages
尽管我设置了但没有调整大小的想法UIViewContentMode
?