I have a problem resizing images from web service (in code below i’m trying to get 400*266 down to 300*200). In detail view controller’s viewDidLoad I add scroll view and image view. Then I add image to image view and change the size of image view’s frame. Result is 300*100 image. Height is always about half of what I want. But if I change dimensions manually in storyboard (not useful for different image dimensions) it works like a charm. What am I missing?
@interface DetailVIewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
....
//adding image and resizing imageview's frame
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:someURL]]];
imageView.image = image;
self.imageView.frame = CGRectMake(10, 20, 300, 200);
....
//further down the code (if it's an issue):
CGSize size = {screenWidth, screenHeight};
self.scrollView.delegate = self;
self.scrollView.contentSize = size;
if you have images with different dimensions, then you need to look at in concept of scale rather than dimension. You adjust the scale of the image as you initialize it, have a look here. Then you when you set the image to the imageView call
[imageView sizeToFit]to make it as fit exactly as the image size.hope this helps.