I setup up a ScrollView as root view for one of my view controllers. When I dragged the scroll view from the Interface builder, the scroll came up with an initial size of 220×120.
In that view controller viewDidLoad method, I have this code.
UIImage *iphone = [UIImage imageNamed:@"iphone4s.jpg"];
imageview = [[UIImageView alloc] initWithImage:iphone];
[self.view addSubview:imageview];
[(UIScrollView*)self.view setContentSize:[iphone size]];
the iphone image size is 600×800.
But the scroll view still is in size 220×120 when the view loads up on the screen. Should I do anything else to stretch the scrollView. Please help.
The property
contentSizeis not the same as the size of the UIScrollView. Normally you’ll have a bigger content size in order to be able to scroll:The inner rect in this sketch is the scroll view size (your 220×120), what you see in the screen, while the outer rect is the actual size of the object (600×800 in your case). Manipulating
contentOffsetpoint (the x in the figure) you can change which portion of the object is visible.If you don’t need the image to be scrollable, you don’t need a UIScrollView at all. Try with the UIImageView, change its
frameand check the different values of itscontentModeproperty.Also, don’t forget that views can auto adjust its size.