Rect size for image size based image iOS Objective C

 Solution:


- (CGRect)contentClippingRect:(UIImageView *)img {

  CGRect imageRect;

  CGFloat scaleX = img.bounds.size.width/img.image.size.width;

  CGFloat scaleY = img.bounds.size.height/img.image.size.height;

  if(scaleX < scaleY) {

    imageRect = CGRectMake(0, (img.bounds.size.height - scaleX*img.image.size.height)*0.5f, img.bounds.size.width, scaleX*img.image.size.height);

  } else {

    imageRect = CGRectMake((img.bounds.size.width-scaleY*img.image.size.width)*0.50, scaleY*img.image.size.width, aspectRatioX*img.image.size.height);


  }

  

  return imageRect;

  }


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift