在缩小ImageView中的图像尺寸时遇到问题。在CollectionViewCell中,ImageView具有以下约束:两个水平空间和两个垂直空间。
第一个屏幕是iOS7,第二个屏幕是iOS8。
ImageURL它是用于通过URL加载图像的自定义类,它可以正常工作,还可以将图像设置为
_clothesImageView.image = [UIImage imageNamed:@"imageName.png"];
- (void)configCellWithClothesModel:(ClothesModel *)clothesModel
{
[_clothesImageView setImageURL:[NSURL URLWithString:clothesModel.imageURL]];
}
衣服型号:
- (instancetype)initWithDict:(NSDictionary *)dict
{
self = [super init];
if (self)
{
_isShop = @(YES);
self.title = [self checkNullAndNill:dict[kTitle]];
self.info = [self checkNullAndNill:dict[kDescription_Short]];
self.artNumber = [self checkNullAndNill:dict[kArtNumber]];
self.afLink = [self checkNullAndNill:dict[kDeeplink1]];
self.imageURL = [self checkNullAndNill:dict[kImg_url]];
_isCart = @(NO);
}
return self;
}
//==============================================================================
- (id)checkNullAndNill:(id)object
{
if (object == nil)
return @"";
else if (object == [NSNull null])
return @"";
else
return object;
}
//==============================================================================
- (UICollectionViewCell *)configCellWithType:(NSString *)type collectionView:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath
{
ClothesCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[type isEqualToString:@"Outfits"] ? @"CellOutfits" : @"Cell" forIndexPath:indexPath];
[cell configCellWithClothesModel:self];
return cell;
}
//==============================================================================
在Xcode6 Interface中,构建器不会向您显示单元的内容视图。CollectionViewCell在iOS7中具有内容视图,并且其框架设置为默认值(0,0,50,50)。
您需要在CollectionViewCell子类中添加此代码,以便contentView自行调整大小
- (void)awakeFromNib
{
[super awakeFromNib];
self.contentView.frame = self.bounds;
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句