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]];
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.
is not the same as the size of the UIScrollView. Normally you’ll have a bigger content size in order to be able to scroll:
+-------------------+ |x------------+ | || | | || | | |+------------+ | | | | | +-------------------+
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
point (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
and check the different values of its
Also, don’t forget that views can auto adjust its size.