微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐