iOS7上的UICollectionViewCell中的UIImageView自动布局问题,但在iOS8上也没关系

ImageView中减少图像大小有问题.
在CollectionViewCell中有ImageView的约束:两个水平和两个垂直空间.
一个屏幕是iOS7,第二个屏幕是iOS8.

ImageURL它是通过URL加载图像的自定义类,它工作正常,也设置了像这样的图像

_clothesImageView.image = [UIImage imageNamed:@"imageName.png"];

    - (void)configCellWithClothesModel:(ClothesModel *)clothesModel
    {
        [_clothesImageView setimageURL:[NSURL URLWithString:clothesModel.imageURL]];
    }

ClothesModel:

- (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中,“界面”构建器不会显示Cell的内容视图.
CollectionViewCell在iOS7中具有内容视图,其框架设置为认值(0,50,50).
您需要在CollectionViewCell子类中添加代码,因此contentView将自行调整大小

- (void)awakeFromNib
{
   [super awakeFromNib];
   self.contentView.frame = self.bounds;
   self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...