3

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. enter image description here enter image description here

ImageURL it's custom class for load image by URL, it works ok, also set a image like

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


//==============================================================================
Iraklii
  • 1,295
  • 13
  • 30
  • give us some code from ClothesModel class. Especially on image part. – hris.to Dec 25 '14 at 08:57
  • Put some code. You are running the code in iPhone 5 or iPhone 6? – Ashish Kakkad Dec 25 '14 at 09:01
  • @hris.to done. Custom class works ok. – Iraklii Dec 25 '14 at 09:11
  • @AshishKakkad iPhone 6 does not support iOS7. I run on all devices with iOS7 and have same problem. – Iraklii Dec 25 '14 at 09:12
  • i think try [imgView.layer setMaskToBound:YES] if its not working then try [imgView setContentMode:] in contentMode there are UIViewContentModeScaleAspectFill, UIViewContentModeScaleAspectFit, and UIViewContentModeScaleToFill and so many but one of these three may help You – Mubin Mall Dec 25 '14 at 09:35
  • @TheMall didn't help. [_clothesImageView setContentMode:UIViewContentModeScaleAspectFill]; [_clothesImageView.layer setMasksToBounds:YES]; [_clothesImageView setImageURL:url]; – Iraklii Dec 25 '14 at 10:22

2 Answers2

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

- (void)awakeFromNib
{
   [super awakeFromNib];
   self.contentView.frame = self.bounds;
   self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
Iraklii
  • 1,295
  • 13
  • 30
zurakach
  • 1,324
  • 1
  • 8
  • 14
0

It can really depends on Autolayout settings.
UIImageViews 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.

Andrea
  • 26,120
  • 10
  • 85
  • 131
  • I have removed all constraints and it's work on iOS7 but when I run on iPhone 6 or 6+ image doesn't increase size. – Iraklii Dec 25 '14 at 10:35
  • You don't need to remove the constraint, but set them correctly – Andrea Dec 25 '14 at 11:04
  • For instance, let's suppose that the imageview should stretch all over the cell content view. The right constarint for the imageview are leading,trailing,top and bottom with constant equal to 0. – Andrea Dec 25 '14 at 11:07
  • Yes I did it. And it was before. – Iraklii Dec 25 '14 at 11:10