Have problem with reducing image size in ImageView. In the CollectionViewCell have ImageView with constraints: two horizontal and two vertical spaces.
First screen is iOS7 and second screen is iOS8.
在ImageView中减少图像大小有问题。在CollectionViewCell中有ImageView的约束:两个水平和两个垂直空间。第一个屏幕是iOS7,第二个屏幕是iOS8。
ImageURL it's custom class for load image by URL, it works ok, also set a image like
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;
}
//==============================================================================
2 个解决方案
#1
7
In Xcode6 Interface builder doesn't show you the content view of the Cell. CollectionViewCell has content view in iOS7 and its frame is set to default values (0,0,50,50).
You need to add this code in CollectionViewCell subclass, so contentView will resize itself
在Xcode6中,“界面”构建器不会显示Cell的内容视图。 CollectionViewCell在iOS7中具有内容视图,其框架设置为默认值(0,0,50,50)。您需要在CollectionViewCell子类中添加此代码,因此contentView将自行调整大小
- (void)awakeFromNib
{
[super awakeFromNib];
self.contentView.frame = self.bounds;
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
#2
0
It can really depends on Autolayout settings.UIImageView
s usually set their sizes based on their intrinsic content size that is set to be the size of the image they are hosting.
If your collection view cell has not the sufficient number of constraints what you see can depend on the autolayout engine implementation on different iOS.
Also check the content mode of the image view as someone stated in the comments.
它实际上取决于Autolayout设置。 UIImageViews通常根据其内在内容大小设置其大小,该内容大小设置为它们托管的图像的大小。如果您的集合视图单元格没有足够数量的约束,您看到的可能取决于不同iOS上的autolayout引擎实现。还要检查评论中所述的图像视图的内容模式。
#1
7
In Xcode6 Interface builder doesn't show you the content view of the Cell. CollectionViewCell has content view in iOS7 and its frame is set to default values (0,0,50,50).
You need to add this code in CollectionViewCell subclass, so contentView will resize itself
在Xcode6中,“界面”构建器不会显示Cell的内容视图。 CollectionViewCell在iOS7中具有内容视图,其框架设置为默认值(0,0,50,50)。您需要在CollectionViewCell子类中添加此代码,因此contentView将自行调整大小
- (void)awakeFromNib
{
[super awakeFromNib];
self.contentView.frame = self.bounds;
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
#2
0
It can really depends on Autolayout settings.UIImageView
s usually set their sizes based on their intrinsic content size that is set to be the size of the image they are hosting.
If your collection view cell has not the sufficient number of constraints what you see can depend on the autolayout engine implementation on different iOS.
Also check the content mode of the image view as someone stated in the comments.
它实际上取决于Autolayout设置。 UIImageViews通常根据其内在内容大小设置其大小,该内容大小设置为它们托管的图像的大小。如果您的集合视图单元格没有足够数量的约束,您看到的可能取决于不同iOS上的autolayout引擎实现。还要检查评论中所述的图像视图的内容模式。