1
votes

Aspect ratio "Scale To Fill" and "Aspect Fit" make the image stretched to whole UIImageView size. How can I use Aspect Fill" to handell UIImageView inside UITableViewCell. UIImageView inside UITableViewCell is running out of the screen in Aspect Fill. I want to make the image to take is original size rather then to stretch but I want to prevent it form overlapping over its lower cell. Rather its better if it goes below the lower cell.

First Scale To Fill Second Aspect Fill

enter image description here I want to use Aspect Fill and gain as below:

enter image description here

I use following to select the image mode

enter image description here

My code

Cell.m

- (void)awakeFromNib {
     _img.clipsToBounds = YES;
    _img.contentMode = UIViewContentModeScaleAspectFill;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
  }

VCUIViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        static NSString *CellIdentifier = @"NoticiasDetailImageCell";
        NoticiasDetailImageCell *cell = (NoticiasDetailImageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
            cell = (NoticiasDetailImageCell *)[nib objectAtIndex:0];
        }
        cell.img.image = self.img;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    }
1
Did my solution below work for you? If yes, please accept the answer. ThanksGurtej Singh

1 Answers

6
votes

You should try to use:

image.clipsToBounds = YES;
image.contentMode = UIViewContentModeScaleAspectFill;

Does it give you the desired results?