gpt4 book ai didi

ios - iOS7 上的 UICollectionViewCell 中的 UIImageView 自动布局问题,但在 iOS8 上没问题

转载 作者:可可西里 更新时间:2023-11-01 17:06:22 25 4
gpt4 key购买 nike

在 ImageView 中减小图像大小时遇到​​问题。在 CollectionViewCell 中有带约束的 ImageView:两个水平空间和两个垂直空间。
第一屏是iOS7,第二屏是iOS8。 enter image description here enter image description here

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 builder 不会向您显示 Cell 的内容 View 。CollectionViewCell 在 iOS7 中具有内容 View ,其框架设置为默认值 (0,0,50,50)。
您需要在 CollectionViewCell 子类中添加此代码,因此 contentView 将自行调整大小

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

关于ios - iOS7 上的 UICollectionViewCell 中的 UIImageView 自动布局问题,但在 iOS8 上没问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27645703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com