title: Image resizing inside tableviewcell
body: <p>I ran into a problem that can not solve 2 days. On the server image and come before inserting them in the box, I cut them on the client to fit the screen. Everything is good but the images change randomly height. Now the height is calculated independently - in proportion to the width.
  Normal image:</p>
  
  <p><a href="https://i.stack.imgur.com/r7BmZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r7BmZ.png" alt="enter image description here"></a></p>
  
  <p>Bad image</p>
  
  <p><a href="https://i.stack.imgur.com/o8whU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o8whU.png" alt="enter image description here"></a></p>
  
  <p>I can not ask explicitly UIImageView because I dynamically I rely all the cells to different devices.</p>
  
  <p>My resize function:</p>
  
  <pre><code>-(UIImage *)resizeImage :(UIImage *)theImage :(CGSize)theNewSize {
  UIGraphicsBeginImageContextWithOptions(theNewSize, NO, 1.0);
  CGFloat height = theImage.size.height;
  CGFloat newHeight = 0;
  newHeight = (theNewSize.width * height) / theImage.size.width;
  newHeight = floorf(newHeight);
  NSLog(@"new height image %f", newHeight);
  [theImage drawInRect:CGRectMake(0, 0, theNewSize.width, newHeight)];
  UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  return newImage;
  }
  </code></pre>
  
  <p>inside layoutSubviews:</p>
  
  <pre><code>if(device == thisDeviceClass_iPhone5) {
      [self.imageView setFrame:CGRectMake(0,0, 320, 255)]; //180
      offset = 0;
      padding = 5;
  } else if(device == thisDeviceClass_iPhone6){
      [self.imageView setFrame:CGRectMake(0,0, 375, 255)]; //211
      offset = 25;
  } else if(device == thisDeviceClass_iPhone6plus) {
      [self.imageView setFrame:CGRectMake(0,0, 414, 255)]; //233
      offset = 40;
  }
  </code></pre>